• Hi,

    I’m trying to display a list of posts at the top of each category page. I’ve figured out how to make that happen, at least in a rough form, but I’m running into the problem that it’s displaying parent category posts even at deeper levels.

    Here is the code that I am using, in my category.php file:

    <?php
    global $post;
    $categories = get_the_category();
    $category = $categories[0];
    $cat_ID = $category->cat_ID;
    
    $myposts = get_posts("numberposts=20&category=$cat_ID");
    ?>
    
    <?php foreach($myposts as $post) :?>
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <?php endforeach; ?>

    Here is an example of the problem. On this page, I would like to only see posts relating to “burgers” where now I get the last 20 food related posts from the entire parent category “eat.”

    http://www.tacomamama.com/v2/?cat=93

    I’d be extremely grateful for any help you can provide. Please let me know if I can provide any more examples.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter tacomamama

    (@tacomamama)

    bump! Help!

    Thread Starter tacomamama

    (@tacomamama)

    Well, I’ve given up on this idea for now. I need to get my site up and running. What appeared to be happening was not only that the top level category was showing, but the top level category for *the first post* which might not be at all related to the category I’m browsing.

    For example: I have a post about Veteran’s Day and schools, it is placed in both the “celebrate” category, and the “schools” category which is a child of “learn.” Since it was the most recent post in the “learn” category, browsing “learn” results in a list of the last 20 posts in the celebrate category.

    For now (and for others trying to do this) I am using Sobek’s Posts in Category plugin:

    http://clockworkblogger.com/sobeks-post-in-category-plugin/

    Which works great but requires that I build a page for each category that I would like to display, it can’t detect which category I’m browsing and display those posts – the category has to be coded in.

    What I would like to have is a nice clean plug in or easy hack that would call the exact category I am currently browsing (whatever it is, without having to create a page for each one and a menu leading to those pages) and display a list of only those posts.

    In the process of researching this I’ve found many other posts by people going around and around this same issue and not getting anywhere. I believe this would be a very useful plugin if anyone wants to take it on.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Display Child Category Posts Only’ is closed to new replies.