0

I've used the basic HTML sitemap code from Yoast. Wondering if it's possible to exclude member-only pages and posts.

<h2 id="pages">Pages</h2>
<ul>
<?php
// Add pages you'd like to exclude in the exclude here
wp_list_pages( array( 'exclude' => '', 'title_li' => '') );
?>
</ul>
<h2 id="posts">Blog Posts</h2>
<ul>
<?php
// Add categories you'd like to exclude in the exclude here
$cats = get_categories('exclude=');
foreach ($cats as $cat) {
  echo "<li><h3>".$cat->cat_name."</h3>";
  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>";
  echo "</li>";
} ?>
</ul>
  • Have you checked the FAQ or the plugin's support forums? – Pat J Apr 7 '14 at 20:58
  • Your answer is not related to my question at all. I'm not using yoast plugins, simply credited him for the code above, picked up at yoast.com/html-sitemap-wordpress – Phantasmix Apr 7 '14 at 21:43
  • How do you define what a member page/post is? – czerspalace Apr 7 '14 at 23:24
  • 2
    If for "member-only pages and posts" you mean posts marked as "private" in backend, that posts/pages are auto-excluded if the person viewing sitemap is not logged. If you want to hide the also for logged users, use the argument post_status=publish Also, please, even if Yoast does it, don't use query_posts. – gmazzap Apr 7 '14 at 23:35
  • 2
    @Phantasmix that answer is related to any query in WordPress. Have you read the bold line on 5th line: "TL;DR don't use query_posts() ever" – gmazzap Apr 8 '14 at 0:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.