Support » Themes and Templates » Have a page template that includes posts?

Have a page template that includes posts?

  • 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?

Viewing 4 replies - 1 through 4 (of 4 total)
  • 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(); ?>

    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.

    Would this be any more complicated than just copy-pasting the loop code so I have two (slightly different) copies of the same thing?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Have a page template that includes posts?’ is closed to new replies.