Code to display posts by category.
-
Hi I am a big newbie to wordpress and getting rather stressed out trying to find answers on google. I want to show my posts relating to differrent topics in their specific category. ie. posts relating to news in the news cateogry, and opinion in opinion category etc.
The problem is I have made a custom category template.
I have put in the following code after my get header:
-
<li class=”page_item”><h1>Recent News</h1>
<?php
$myposts = get_posts(‘numberposts=10&category=’);
foreach($myposts as $post) :
setup_postdata($post);
?>
<?php if ( ! in_category(6) ) { ?>
<li class=’page_item’>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”><?php the_title(); ?>
<?php } ?>
<?php endforeach; ?>This is allowing me to see links to my posts in a given cateogry, eg. https://www.integrateni.com/category/news but I would like them in list form and with a thumbnail and excerpt. Does anyone have any idea how change the code to allow this.
My other BIG problem is that the same posts are showing up in each of my cateogries, is it necessary to make a separate category.php for each cateory, or is there a way of changing the code so it does this automatically when I create a new category. ie. above in my h1 it says
Recent News
but I only want this for the news category, and would like it to say opinion for the opinion category, community for the community category etc.
I hope someone understands what I am trying to explain and can help me out.
Many thanks in advance
- The topic ‘Code to display posts by category.’ is closed to new replies.