WordPress.org

Ready to get started?Download WordPress

Forums

How do I display posts from a specific category on a page? (6 posts)

  1. shoesandsocks
    Member
    Posted 6 years ago #

    Hi,

    I was wondering if someone could help me out with something on a website I am trying to build - http://gillinghamband.org/gillpress/ - I have a fairly rubbish understanding of php so am struggling a bit...!

    I have a page called 'news' and a page called 'articles' (each using their own template).

    Currently both pages pull through all posts. What I would like is for the news page to pull through only posts in the 'news' category and the 'articles' page to only pull through posts in the 'articles' category.

    What do I need to add to the page templates to make this happen?

    Thanks,

    Lisa :-)

  2. ajennell
    Member
    Posted 6 years ago #

    I know the fallowing code will call up the recent entries for a specific post. Just change CATEGORYNAME to the name of the category. Then enter how many posts you would like shown. I'm sure this isn't what you want, but I hope it helps.

    <?php query_posts('category_name=CATEGORYNAME&showposts=5');
    while (have_posts()) : the_post();
      // do whatever you want
    ?>
    <b><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
    <?php
    endwhile;
    ?>
  3. shoesandsocks
    Member
    Posted 6 years ago #

    Thanks, that was really helpful! :-)

    I've now got the News items pulling through on the News page and the Articles on the Articles page.

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Or you could simply use Category Templates in the first place, like the system was designed to do.

  5. shoesandsocks
    Member
    Posted 6 years ago #

    Thanks, I will have a read, it looks very useful!

    ...Not sure how I managed to miss that in my searching...

  6. krushinfo
    Member
    Posted 5 years ago #

    Hey

    This code worked great for me - I wanted to put a list of the latest news from a specific category on my front page.

    Does anyone know how I include 2 or 3 categories, I imagine I have to change something here:

    <?php query_posts('category_name=CATEGORYNAME&showposts=5');

    ????

Topic Closed

This topic has been closed to new replies.

About this Topic