HTML 站点地图:帮助访问者快速找到您的内容

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

HTML Sitemap
HTML Sitemap

插件方案

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

AIOSEO Pro HTML sitemap
AIOSEO Pro HTML sitemap
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/[email protected]/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>

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注