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).
try below code:
If you are using
category.php
, you can omit thequery_posts
and it will auto fill in the posts for you.try
Try this, this is better solution for this and you can also use it to show Related Post by a category id…
Just call the function that mentioned below by using this line. Put this in your template or page.php/single.php file.
Call by put this line:
related_post_title('enter cat id here..');
Here is the Function and put this in
function.php
file.Related posts function:
If any query please let me know, i will help you…