[resolved] Loop help with nested categories (2 posts)

  1. jcotter
    Posted 6 years ago #

    Quick Q.. (i hope)..

    I've got several nested categories from which i am including several (but not all) child categories as a "What's New" section of my site. I'm trying to have it write a <p> tag prior to each loop, based on the child category.

    Here's what i've been trying to do:

    <?php query_posts /* enter # of posts here----> */('showposts=3&cat=15,27,28,29');/* For a full list of possible arguments you can pass to query_posts see http://codex.wordpress.org/Template_Tags/query_posts */
    global $more;    // Declare global $more (before the loop).
    $more = 0;       // Set (inside the loop) to display content above the more tag.
    <?php while ( have_posts() ) : the_post(); ?>
    <?php if (is_category('15')) { ?>
    <p class="category_leadin">Article Review:</p>
    <?php } elseif (is_category('27')) { ?>
    <p class="category_leadin">Book Review:</p>
    <?php } elseif (is_category('28')) { ?>
    <p class="category_leadin">Video Review:</p>
    <?php } elseif (is_category('29')) { ?>
    <p class="category_leadin">Website Review:</p>
    <?php } else { ?>
    <?php } ?>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a><br />
    <?php the_content('Read more...'); ?>
    <?php endwhile; ?>

    This is how it should ideally output:

    Category name

    [repeat loop]

    Problem is, its only returning the parent category (in this case "Reviews"), and not the child category )ex: "book reviews," or "Site reviews."

    Does this make sense? Can anyone help me sort this out?

    Thanks in advance for any insight you can offer.

  2. esmi
    Forum Moderator
    Posted 6 years ago #

    Well, you're asking query_posts to only show 3 posts, so if the first 3 posts all happen to be in the Review category, that's all you'll get.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.