从wordpress站点地图中排除页面


Exclude page from a wordpress sitemap

我在网上看到一个用WordPress创建站点地图的教程。它做了我想要的-它列出了网站上的所有页面和帖子,但我想知道是否有可能从站点地图中排除一个页面。在这种情况下,我想排除站点地图链接。这可能吗?我已经包含了下面站点地图的代码。

<?php
/*
Template Name: Sitemap
*/
get_header(); ?>

<?php if ( have_posts() ) : while( have_posts() ) : the_post();
    the_content();
endwhile; endif; ?>
<h2>Pages</h2>
<ul>
<?php
// Add pages seprated with comma[,] that you'd like to hide to display on sitemap
wp_list_pages(
  array(
    'exclude' => '',
    'title_li' => '',
  )
);
?>
</ul>
<h2>Posts</h2>
<?php
// Add categories seprated with comma (,) you'd like to hide to display on sitemap
$cats = get_categories('exclude=');
foreach ($cats as $cat) {
  echo "<ul>";
  query_posts('posts_per_page=-1&cat='.$cat->cat_ID);
  while(have_posts()) {
    the_post();
    $category = get_the_category();
    // Only display a post link once, even if it's in multiple categories
    if ($category[0]->cat_ID == $cat->cat_ID) {
      echo '<li><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
    }
  }
  echo "</ul>";
}
?>
<?php get_footer(); ?>

我知道代码中的注释给了我一些关于在哪里列出我想要隐藏的页面的想法,但是我不确定如何做到这一点。如果有人能帮助我,我将不胜感激。

许多谢谢。

如果你想从你的站点地图中排除页面,你必须在这里写

   wp_list_pages(
      array(
        'exclude' => 'ID1, ID2',
        'title_li' => '',
      )
    );

ID1和ID2是你在WordPress上的页面id