Wordpress displays posts of category ID

Posted by Miker on Stack Overflow See other posts from Stack Overflow or by Miker
Published on 2012-07-02T03:07:19Z Indexed on 2012/07/02 3:15 UTC
Read the original article Hit count: 507

Filed under:
|
|
|
|

Can't seem to find the right answer for what I thought would be trivial.

I have some categories arranged like this...

Parent Category 1
- Child Category 1
- Child Category 2
- Child Category 3

...and I have some posts that are in Child Category 2. I want my page to display all posts from the category I am currently in.

This is what I am doing right now:

<?php
query_posts('cat=2&showposts=10');
    if (have_posts()) : while (have_posts()) : the_post(); ?>      
    <div class="timeline">
    <h3><?php the_title(); ?></h3>
    <?php the_content();?>
    <?php endwhile; else: ?>
    <?php _e('No Posts Sorry.'); ?>
    <?php endif; ?>
</div>

As you can see I am having to manually specify the category (cat=2), but instead I want it to automatically detect the category I am already in and display the posts (that way if I'm in a different category it will display those posts).

Any suggestions?

Thanks in advance. (SO Community = Awesome Sauce).

© Stack Overflow or respective owner

Related posts about Wordpress

Related posts about parent