Mr_Cynical
Member
Posted 9 months ago #
Is it possible to have a page template that can also fetch posts? I know that's not the clearest explanation. What I want to have is a page template that will display the page's title and content, but can also then fetch posts in a specified way (in my case it's fetching a specific category of posts)and display them underneath. Is this possible?
You can make a page template that works just like the main index page and then add a query for that particular category so only those posts show.
For example, if you make a new template using the code from you main index template you can add something like the following
<?php query_posts('category_name=wordpress&showposts=5'); ?>
right before the loop starts
<?php while (have_posts()) : the_post(); ?>
Mr_Cynical
Member
Posted 9 months ago #
What I was wanting to do is have a page template which displays that page's content as normal, and then under that content displays a particular category of posts. Could I do that essentially by reversing your code? Take the code from a normal 'single page' template, and then put the query_posts line under the loop?
The query posts has to come before a loop so you could make a second loop below the first one that only pulls the posts from the designated category.
Mr_Cynical
Member
Posted 9 months ago #
Would this be any more complicated than just copy-pasting the loop code so I have two (slightly different) copies of the same thing?