欢迎您光临自学哈网,只为分享网络知识教程,供大家学习参考!

「自学哈网」WordPress网站的HTML 站点地图:帮助访问者快速找到您的内容

作者 : 自学哈 本文共2101个字,预计阅读时间需要6分钟 2022-11-26 共100人阅读
也想出现在这里? 联系我们

站点地图sitemap很多方案都可以实现,但是HTML 站点地图(HTML Sitemap)不同于XML Sitemap,HTML 站点地图更便于用户阅读,当然也是利于搜索引擎抓取,对SEO很有帮助。那么怎么实现,以此帮助访问者快速找到您的内容呢?

HTML Sitemap

插件方案

All in One SEO Pro (AIOSEO Pro)目前已经支持了HTML Sitemap的功能。

AIOSEO Pro HTML sitemap

代码方案

用自定义页面模板的方法,新建一个page页面php文件,然后在后台页面发布一篇页面,选择这个页面模板即可。

<?php
/*
Template Name: All
*/
?>
<!DOCTYPE html>
<html lang=\"zh-CN\">
<head>
  <meta charset=\"UTF-8\">
  <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">
  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
  <title>HTML Sitemaps</title>
  <link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css\">
</head>
<body <?php body_class(\'m-3\');?>>
  <div class=\"container\">
    <h1 class=\"fs-3\">Sitemap</h1>
    <div class=\"item\">
      <h2 class=\"fs-4\">Posts</h2>
      <ul class=\"lh-lg\">
        <?php
        $the_query = new WP_Query(
          array(
            \'post_type\' => \'post\',
            \'posts_per_page\' => -1,
            \'orderby\' => \'date\',
            \'order\' => \'DESC\'
          )
        );
        if ($the_query->have_posts()) :
          while ($the_query->have_posts()) : $the_query->the_post();
            ?>
            <li><a href=\"<?php the_permalink(); ?>\" rel=\"bookmark\" title=\"Permanent Link to <?php the_title_attribute(); ?>\"><?php the_title(); ?></a></li>
          <?php endwhile; else : ?>
            <p><?php esc_html_e( \'Sorry, no posts matched your criteria.\' ); ?></p>
          <?php endif; ?>
      </ul>
    </div>
    <!-- .item -->
    <div class=\"item\">
      <h2 class=\"fs-h5\">Pages</h2>
      <ul class=\"lh-lg\">
        <?php
        $the_query = new WP_Query(
          array(
            \'post_type\' => \'page\',
            \'posts_per_page\' => -1,
            \'orderby\' => \'date\',
            \'order\' => \'DESC\'
          )
        );
        if ($the_query->have_posts()) :
          while ($the_query->have_posts()) : $the_query->the_post();
            ?>
            <li><a href=\"<?php the_permalink(); ?>\" rel=\"bookmark\" title=\"Permanent Link to <?php the_title_attribute(); ?>\"><?php the_title(); ?></a></li>
          <?php endwhile; else : ?>
            <p><?php esc_html_e( \'Sorry, no posts matched your criteria.\' ); ?></p>
          <?php endif; ?>
      </ul>
  </div>
  <!-- .item -->
  <div class=\"item\">
    <h2 class=\"fs-h5\">Categories</h2>
    <ul class=\"lh-lg\">
      <?php wp_list_categories(
        array(
          \'title_li\' => \'\',
          \'show_count\' => true,
          \'hide_empty\' => false,
          \'orderby\' => \'name\',
          \'order\' => \'ASC\'
        )
      ); ?>
    </ul>
  </div>
  <!-- .item -->
  <?php echo \'<!-- \' . get_num_queries() . \' queries in \' . timer_stop( 0, 5 ) . \' seconds. -->\'; ?>
</body>
</html>
本站声明:
本站所有资源来源于网络,分享目的仅供大家学习和交流!如若本站内容侵犯了原著者的合法权益,可联系邮箱976157886@qq.com进行删除。
自学哈专注于免费提供最新的分享知识、网络教程、网络技术的资源分享平台,好资源不私藏,大家一起分享!

自学哈网 » 「自学哈网」WordPress网站的HTML 站点地图:帮助访问者快速找到您的内容
也想出现在这里? 联系我们
© 2022 Theme by - 自学哈网 & WordPress Theme. All rights reserved 浙ICP备2022016594号