Display Only Posts From A Certain Category
I realy had to dig deep to find this so I thought I would put it up here so I wouldn’t forget as well for you to have it.
What I wanted was to divide the homepage in several sections and it should diplay only the newest posts and if possible only at the place I wanted it.
The posts are called in the loop and normally ou have one loop on your page that goes thru all your posts and displays it like that. But you can limit the posts and also you can specify how many posts and from which category.
The code to do that is like this ( i have removed the opening php part as I have a plugin called exec php which will try to execute the php and in this case I do not want that)
–open php– query_posts(’cat=x&showposts=y‘); while (have_posts()) : the_post(); –end php–
here you can call the title, content, date authur etc etc
–open php– endwhile; –end php—
at cat=X you look at the number of the category in Manage -> Categories and fill in the id number of your category at x. At showpost=y you change the y into the number of posts you want to show from the category. So if you want to show 3 posts from category products which has an idnumber of fi 6 it would be query_posts(’cat=6&showposts=3′);
Posted on April 15th, 2007 by edwin
Filed under: Code
























Leave a Reply