簡體   English   中英

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM