从 wordpress 站点地图中排除页面

Exclude page from a wordpress sitemap

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

<?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。