Title: Code to display posts by category.
Last modified: August 22, 2016

---

# Code to display posts by category.

 *  [ZoeSC](https://wordpress.org/support/users/zoesc/)
 * (@zoesc)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/code-to-display-posts-by-category-1/)
 * 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. [http://www.integrateni.com/category/news](http://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

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

 *  Thread Starter [ZoeSC](https://wordpress.org/support/users/zoesc/)
 * (@zoesc)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/code-to-display-posts-by-category-1/#post-5622507)
 * Hi again, I have been playing around and have managed to get the links to the
   posts in the category page to show in a list form with an excerpt by adding the
   following bit of code
 * > </h3><?php the_excerpt(); ?>
 * [http://www.integrateni.com/category/news](http://www.integrateni.com/category/news)
 * I still have not figured out what code is needed to generate a thumbnail of the
   first photo of the post to show with the excerpt. I would be grateful of any 
   help.
 * I also feel it looks rather untidy and was wondering if anyone could suggest 
   how to make it that each link shows in a block of colour or with a boarder, all
   the same size.
 * I am still having trouble with the fact that all posts are showing up in all 
   categories. Is it necessary to have separate category template PHPs or is there
   a way round this. The code I have used so far is in the above post.
 * Thanks
 *  [Peter Lawrenson](https://wordpress.org/support/users/lorro/)
 * (@lorro)
 * [11 years, 8 months ago](https://wordpress.org/support/topic/code-to-display-posts-by-category-1/#post-5622608)
 * Can’t help with the code except to point to this example which may give some 
   clues:
    [http://codex.wordpress.org/User:Esmi/Twenty_Eleven_Page_of_Posts](http://codex.wordpress.org/User:Esmi/Twenty_Eleven_Page_of_Posts)
 * Maybe I can help with the problem if you are open to another theme. Have a look
   at virtue.
    [https://wordpress.org/themes/virtue](https://wordpress.org/themes/virtue)
 * It has a blog page template built-in. So you create a page just for your abc 
   category posts, choose the blog page template, save, then go to the category 
   select drop-down box and pick the abc category. That’s it, no code.
 * Other themes may also come with blog page templates.

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

 The topic ‘Code to display posts by category.’ is closed to new replies.

## Tags

 * [new topic](https://wordpress.org/support/topic-tag/new-topic/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [Peter Lawrenson](https://wordpress.org/support/users/lorro/)
 * Last activity: [11 years, 8 months ago](https://wordpress.org/support/topic/code-to-display-posts-by-category-1/#post-5622608)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
