Joe主题404页面必须优化的理由

拥有用Typecho搭建网站的站长们,稍微用过 Joe这款主题的都知道主题本身优点多多,通过几行代码就能实现多样式化的文章页。然而虽然一直有更新,但他的SEO一直做得比较迷惑。比方说今天要进行SEO优化的404页面,真就Get不到主题作者的出发点是哪样。

先上点眼药

这是Joe 自带的404页面效果图:

Typecho Joe主题404页面SEO优化

再看看实现代码:

Typecho Joe主题404页面SEO优化

展开查看Joe原404页面代码
<!DOCTYPE html><html lang="zh-CN" style="width: 100%;height: 100%"><head><?php $this->need('public/include.php'); ?></head><body style="width: 100%;height: 100%"><svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 1920 1920" preserveAspectRatio="xMidYMid meet"><defs><clipPath id="animationMask_GAJPot1fdg"><rect width="1920" height="1920" x="0" y="0"></rect></clipPath>
......
代码太多字符,本主题无法显示
......
</body></html>

先不说页面效果,就这代码量,应该可以吓退99%的小白了吧

84498个字符,只为实现一张看起来还可以的404图片,真的好想跟上大神的脑回路~

扯远了,进入正题

必须优化这404页面的理由如下:

  • 1.404页面元素过于单一,既没有返回首页的链接,也没有给出任何与网站内容相关的信息,对访客极度不友好
  • 2.假设所有站长都不改变Joe的原生404页面,你可以想像这一页面在搜索引擎上的“重复率”
  • 3.代码量达到了惊人的84498个字符,然而对网站的运营来说显得毫无意义,404页面跟空白页起到的作用雷同

优化404页面的步骤

终上所述,既然404页面必须优化,那么具体如休实施就有讲究了。

由于博主是小白,不懂前端,也不太了解后端实现的细则,404页面的优化方式,最好的办法就是用现成的代码

暂时想到两种

  • 1.白嫖现成的万用404页面,但可能会出现页面与网站不契合的现像。但至少对访客是友好的,能提供返回首页,最新文章等一些信息。
  • 2.用现成的joe的某个页面,拿来主义,把侧边样、header、footer等拿过来,只改内容展示(当然包含404错误信息了)。

一、直接用现成的404页面

这里随便找了个还可以的,仓库地址:https://github.com/qine233/404-typecho

效果图如下:

Typecho Joe主题404页面SEO优化

可以看到,该有的404提示有,其他“发生错误的原因”、”联系方式”、”网站导航”、”最新文章”,该有的SEO要素基本都涵盖了。

使用方法

很简单,直接下载并上传到网站,文件目录结构如下:

Typecho Joe主题404页面SEO优化

所有文件刚好跟JOE主题的目录文件不冲突,上传到网站主题根目录(~typecho根目录/www/usr/themes/Joe),并复盖404.php页面即可。

当然了,里面的内容是随便修改的。

不足之处

就是,风格与JOE不搭。

二、直接用Joe主题原代码

像上面说的一样,这方法就是直接修改Joe的404页面,找个页面把四肢拿过来。

实现方法:

1.选定拿来的页面,这里选的是index.php

原Joe主题 index.php代码如下:

点击查看Joe主题 index.php
<?php

/**
 * “ 心中无女人,代码自然神 - 78.AL ” <br /> “ 环境要求:PHP 5.4 ~ 7.4 ”
 * @package Joe
 * @author Joe
 * @link https://78.al
 */

?>
<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <?php $this->need('public/include.php'); ?>
  <link href="<?php _getAssets('assets/lib/[email protected]/swiper.min.css'); ?>" rel="stylesheet" />
  <script src="<?php _getAssets('assets/lib/[email protected]/swiper.min.js'); ?>"></script>
  <script src="<?php _getAssets('assets/lib/[email protected]/wow.min.js'); ?>"></script>
  <link href="<?php _getAssets('assets/css/joe.index.min.css'); ?>" rel="stylesheet">
  <script src="<?php _getAssets('assets/js/joe.index.min.js'); ?>"></script>
</head>

<body>
  <div id="Joe">
    <?php $this->need('public/header.php'); ?>
    <div class="joe_container">
      <div class="joe_main">
        <div class="joe_index">
          <?php
          $carousel = [];
          $carousel_text = $this->options->JIndex_Carousel;
          if ($carousel_text) {
            $carousel_arr = explode("\r\n", $carousel_text);
            if (count($carousel_arr) > 0) {
              for ($i = 0; $i < count($carousel_arr); $i++) {
                $img = explode("||", $carousel_arr[$i])[0];
                $url = explode("||", $carousel_arr[$i])[1];
                $title = explode("||", $carousel_arr[$i])[2];
                $carousel[] = array("img" => trim($img), "url" => trim($url), "title" => trim($title));
              };
            }
          }
          $recommend = [];
          $recommend_text = $this->options->JIndex_Recommend;
          if ($recommend_text) {
            $recommend_arr = explode("||", $recommend_text);
            if (count($recommend_arr) === 2) $recommend = $recommend_arr;
          }
          ?>
          <?php if (sizeof($carousel) > 0 || sizeof($recommend) === 2) : ?>
            <div class="joe_index__banner">
              <?php if (sizeof($carousel) > 0) : ?>
                <div class="swiper-container">
                  <div class="swiper-wrapper">
                    <?php foreach ($carousel as $item) : ?>
                      <div class="swiper-slide">
                        <a class="item" href="<?php echo $item['url'] ?>" target="_blank" rel="noopener noreferrer nofollow">
                          <img width="100%" height="100%" class="thumbnail lazyload" src="<?php _getLazyload() ?>" data-src="<?php echo $item['img'] ?>" alt="<?php echo $item['title'] ?>" />
                          <div class="title"><?php echo $item['title'] ?></div>
                          <svg class="icon" viewBox="0 0 1026 1024" xmlns="http://www.w3.org/2000/svg" width="18" height="18">
                            <path d="M784.3 1007.961a33.2 33.2 0 0 1-27.106-9.062L540.669 854.55 431.766 962.813c-9.062 9.062-36.168 18.044-45.23 9.062a49.72 49.72 0 0 1-27.106-45.23V727.763a33.2 33.2 0 0 1 9.463-27.106l343.071-370.578a44.748 44.748 0 0 1 63.274 63.274l-334.17 361.515v72.175l63.273-54.211a42.583 42.583 0 0 1 54.212-9.062l198.64 126.386L910.847 140.34 151.647 510.837 323.343 619.34c18.044 9.062 27.106 45.23 9.062 63.273-9.062 18.044-45.23 27.106-63.273 18.044L34.082 547.005c-8.981-8.982-18.043-17.723-18.043-36.168s9.062-27.105 27.105-36.167l903.79-451.815c18.043-9.062 36.167-9.062 45.229 0 18.284 9.223 18.284 27.106 18.284 45.15L829.69 971.794c0 18.043-9.062 27.105-27.105 36.167z" />
                          </svg>
                        </a>
                      </div>
                    <?php endforeach; ?>
                  </div>
                  <div class="swiper-pagination"></div>
                  <div class="swiper-button-next"></div>
                  <div class="swiper-button-prev"></div>
                </div>
              <?php endif; ?>
              <?php if (sizeof($recommend) === 2) : ?>
                <div class="joe_index__banner-recommend <?php echo sizeof($carousel) === 0 ? 'noswiper' : '' ?>">
                  <?php foreach ($recommend as $cid) : ?>
                    <?php $this->widget('Widget_Contents_Post@' . $cid, 'cid=' . $cid)->to($item); ?>
                    <figure class="item">
                      <a class="thumbnail" href="<?php $item->permalink() ?>" title="<?php $item->title() ?>">
                        <img width="100%" height="100%" class="lazyload" src="<?php _getLazyload(); ?>" data-src="<?php echo _getThumbnails($item)[0]; ?>" alt="<?php $item->title() ?>" />
                      </a>
                      <figcaption class="information">
                        <span class="type">推荐</span>
                        <div class="text"><?php $item->title() ?></div>
                      </figcaption>
                    </figure>
                  <?php endforeach; ?>
                </div>
              <?php endif; ?>
            </div>
          <?php endif; ?>
          <?php if ($this->options->JIndex_Hot === "on") : ?>
            <?php $this->widget('Widget_Contents_Hot@Index', 'pageSize=4')->to($item); ?>
            <div class="joe_index__hot">
              <ul class="joe_index__hot-list">
                <?php while ($item->next()) : ?>
                  <li class="item">
                    <a class="link" href="<?php $item->permalink(); ?>" title="<?php $item->title(); ?>">
                      <figure class="inner">
                        <span class="views"><?php echo number_format($item->views); ?> ℃</span>
                        <img width="100%" height="120" class="image lazyload" src="<?php _getLazyload(); ?>" data-src="<?php echo _getThumbnails($item)[0]; ?>" alt="<?php $item->title(); ?>" />
                        <figcaption class="title"><?php $item->title(); ?></figcaption>
                      </figure>
                    </a>
                  </li>
                <?php endwhile; ?>
              </ul>
            </div>
          <?php endif; ?>
          <?php
          $index_ad_text = $this->options->JIndex_Ad;
          $index_ad = null;
          if ($index_ad_text) {
            $index_ad_arr = explode("||", $index_ad_text);
            if (count($index_ad_arr) === 2) $index_ad = array("image" => trim($index_ad_arr[0]), "url" => trim($index_ad_arr[1]));
          }
          ?>
          <?php if ($index_ad) : ?>
            <div class="joe_index__ad">
              <a class="joe_index__ad-link" href="<?php echo $index_ad['url'] ?>" target="_blank" rel="noopener noreferrer nofollow">
                <img width="100%" height="200" class="image lazyload" src="<?php _getLazyload() ?>" data-src="<?php echo $index_ad['image'] ?>" alt="<?php echo $index_ad['url'] ?>" />
                <span class="icon">广告</span>
              </a>
            </div>
          <?php endif; ?>

          <div class="joe_index__title">
            <ul class="joe_index__title-title">
              <li class="item" data-type="created">最新文章</li>
              <li class="item" data-type="views">热门文章</li>
              <li class="item" data-type="commentsNum">评论最多</li>
              <li class="item" data-type="agree">点赞最多</li>
              <li class="line"></li>
            </ul>
            <?php
            $index_notice_text = $this->options->JIndex_Notice;
            $index_notice = null;
            if ($index_notice_text) {
              $index_notice_arr = explode("||", $index_notice_text);
              if (count($index_notice_arr) === 2) $index_notice = array("text" => trim($index_notice_arr[0]), "url" => trim($index_notice_arr[1]));
            }
            ?>
            <?php if ($index_notice) : ?>
              <div class="joe_index__title-notice">
                <svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="20" height="20">
                  <path d="M656.261 347.208a188.652 188.652 0 1 0 0 324.05v-324.05z" fill="#F4CA1C" />
                  <path d="M668.35 118.881a73.35 73.35 0 0 0-71.169-4.06l-310.01 148.68a4.608 4.608 0 0 1-2.013.46h-155.11a73.728 73.728 0 0 0-73.728 73.636v349.64a73.728 73.728 0 0 0 73.728 73.636h156.554a4.68 4.68 0 0 1 1.94.43l309.592 143.196a73.702 73.702 0 0 0 104.668-66.82V181.206a73.216 73.216 0 0 0-34.453-62.326zM125.403 687.237v-349.64a4.608 4.608 0 0 1 4.608-4.608h122.035v358.882H130.048a4.608 4.608 0 0 1-4.644-4.634zm508.319 150.441a4.608 4.608 0 0 1-6.564 4.193L321.132 700.32V323.773l305.97-146.723a4.608 4.608 0 0 1 6.62 4.157v656.471zM938.26 478.72H788.01a34.509 34.509 0 1 0 0 69.018H938.26a34.509 34.509 0 1 0 0-69.018zM810.01 360.96a34.447 34.447 0 0 0 24.417-10.102l106.245-106.122a34.524 34.524 0 0 0-48.84-48.809L785.587 302.08a34.509 34.509 0 0 0 24.423 58.88zm24.417 314.609a34.524 34.524 0 1 0-48.84 48.814L891.832 830.52a34.524 34.524 0 0 0 48.84-48.809z" fill="#595BB3" />
                </svg>
                <a href="<?php echo $index_notice['url'] ?>" target="_blank" rel="noopener noreferrer nofollow"><?php echo $index_notice['text'] ?></a>
              </div>
            <?php endif; ?>
          </div>
          <div class="joe_index__list" data-wow="<?php $this->options->JList_Animate() ?>">
            <ul class="joe_list"></ul>
            <ul class="joe_list__loading">
              <li class="item">
                <div class="thumbnail"></div>
                <div class="information">
                  <div class="title"></div>
                  <div class="abstract">
                    <p></p>
                    <p></p>
                  </div>
                </div>
              </li>
              <li class="item">
                <div class="thumbnail"></div>
                <div class="information">
                  <div class="title"></div>
                  <div class="abstract">
                    <p></p>
                    <p></p>
                  </div>
                </div>
              </li>
            </ul>
          </div>
        </div>
        <div class="joe_load">查看更多</div>
      </div>
      <?php $this->need('public/aside.php'); ?>
    </div>
    <?php $this->need('public/footer.php'); ?>
  </div>
</body>

</html>

2.拼接404.php

去掉无关的选项,拿点有用的代码:

<!DOCTYPE html>
<html lang="zh-cn">

<head>
  <?php $this->need('public/include.php'); ?>
  <link href="<?php _getAssets('assets/lib/[email protected]/swiper.min.css'); ?>" rel="stylesheet" />
  <script src="<?php _getAssets('assets/lib/[email protected]/swiper.min.js'); ?>"></script>
  <script src="<?php _getAssets('assets/lib/[email protected]/wow.min.js'); ?>"></script>
  <link href="<?php _getAssets('assets/css/joe.index.min.css'); ?>" rel="stylesheet">
  <script src="<?php _getAssets('assets/js/joe.index.min.js'); ?>"></script>
</head>

<body>
<div id="Joe">
    <?php $this->need('public/header.php'); ?>
    <div class="joe_container">
        <div class="joe_main">
            <div class="joe_index">
                <ul class="list">
                    <li class="joe_list__item wow default">
                        //这里添加你想要的内容,比如一张404错误图片。
                        //经测试,这里class中default样式,图片会很大,single则正常
                    </li>
                </ul>
            </div>
        </div>
        <?php $this->need('public/aside.php'); ?>
    </div>
    <?php $this->need('public/footer.php'); ?>
</div>

关于如何取代码,可F12自行调试:

Typecho Joe主题404页面SEO优化

3.最终404.php代码

拿张404的图片测试,然后在最顶部添加<?php $this->response->setStatus(200); ?>,告诉搜索引擎页面能被正确访问。

最后成品的404.php如下:

<!DOCTYPE html>
<html lang="zh-cn">

<head>
  <?php $this->need('public/include.php'); ?>
  <link href="<?php _getAssets('assets/lib/[email protected]/swiper.min.css'); ?>" rel="stylesheet" />
  <script src="<?php _getAssets('assets/lib/[email protected]/swiper.min.js'); ?>"></script>
  <script src="<?php _getAssets('assets/lib/[email protected]/wow.min.js'); ?>"></script>
  <link href="<?php _getAssets('assets/css/joe.index.min.css'); ?>" rel="stylesheet">
  <script src="<?php _getAssets('assets/js/joe.index.min.js'); ?>"></script>
</head>

<body>
<div id="Joe">
    <?php $this->need('public/header.php'); ?>
    <div class="joe_container">
        <div class="joe_main">
            <div class="joe_index">
                <ul class="list">
                    <li class="joe_list__item wow single">
                        <div class="line"></div>
                        <div class="thumbnail">
                            <img width="100%" height="100%" class=" ls-is-cached lazyloaded" src="https://cdnzct.zctou.com/gh/zctou21/blogimgs/imgs/zctou/joetheme/202303160613534.webp"  alt="404!找不到当前页面">
                        </div>
                    </li>
                </ul>
            </div>
        </div>
        <?php $this->need('public/aside.php'); ?>
    </div>
    <?php $this->need('public/footer.php'); ?>
</div>

不足之处

由于不懂前端,修改起样式非常麻烦还达不到效果。

这种方法不适合小白,浪费时间不说,还起不到想要的效果,毕竟后续调用最新文章,文章分类等都是技术活。

文章目录