• I’m struggling with the PHP for a query I’d like to put in my sidebar to show posts with the Category ‘Featured’ based on the current Category.

    This is what I have:

    <?php if ( have_posts() ) { the_post(); rewind_posts(); } ?>
    
    <?php if (is_home()) { ?>
     <!-- no featured posts -->
    <?php } else { ?>
     <?php if (in_category('London & Brighton Marathons')) { query_posts('cat=4,5'); } ?>
     <!-- featured posts -->
     <h2>Featured Posts</h2>
     <ul>
      <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
      <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
      <?php endwhile; ?>
     </ul>
    <?php endif; ?>

    Internet Explorer tells me I’ve got a parse error, but I can’t see what’s wrong with it. Can anyone else? Any help would be gratefully appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You can’t if (have_posts()) : while (have_posts()) : the_post(); twice! Perhaps you need to read up on Multiple Loops?

    I’d like to put in my sidebar to show posts with the Category ‘Featured’ based on the current Category.

    That needs a bit of clarifying…

    Are you displaying a single post, and if that single post has the category London & Brighton Marathons, then display posts from category 4 and 5

    or

    are you displaying a category archive, and if the category displayed is London & Brighton Marathons, then display posts from category 4 and 5

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How To Show Category Posts In Sidebar’ is closed to new replies.