Support » Developing with WordPress » show only one category from specific parent when listing posts

  • Resolved jesseisrad

    (@jesseisrad)


    Hello,

    I’m trying to use WP as sort of a multiblog by creating parent category: Blogs with sub cats of “Free Agency” and “Beltway Outsider”. Simple enough, but posts can be assigned one of those child cats, but also some other ones.

    What I’d like to do is have a list of only those posts that are in that parent cat (Blogs), which I have done, but then have a call out to see the rest of that “blog” by linking to that child cat and ONLY that child cat.

    Example: http://img.skitch.com/20100408-fjp7s1jfiggeatdqcjy8b9ky95.png

    Code I’m using:

    <?php $blogs_query = new WP_Query('cat=2194&showposts=10');
    	if ($blogs_query->have_posts()) :
    	while ($blogs_query->have_posts()) : $blogs_query->the_post(); ?>
    
     <?php
    global $more;
    $more = 0;
    ?>
    
    <h3 class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
    <?php
    $blog = get_the_category('category_parent=2194');
    $blog[0]->cat_name;
    ?>
    
    <div class="blog-title">from <a href="/blogs/<?php echo $blog[0]->category_nicename;?>"><?php echo $blog[0]->cat_name;?></a></div>
    
    <div class="clear">	</div>
    
    <?php endwhile; endif;?>

    So the problem is that it’s just pulling out the first category listed, which 90% of the time is the correct one but sometimes (as circled) it pulls in some other category.

    I need a way to list only categories from a particular parent. Any ides?

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘show only one category from specific parent when listing posts’ is closed to new replies.