Posts Template Page

For some reason the any template page won’t pull the posts. When I put the loop on any page it pulls the page content (which only includes the title) and not the post content. I can’t change the index page since it’s being used for a couple of the plugins so I have to have a specific template that pulls the post image, title and excerpt and for some reason it has stopped pulling anything from the posts. Using Sage 8.5.1

I’m not really sure what you’re talking about here. Are you referring to your previous post? If you are, then yes, it won’t work as-is as a page template–I’d assumed you were using it for front-page.php or something similar, where the list of posts was already available in the Loop.

On a page template you will have to provide a custom WP_Query, since the one loaded with that page is, correctly, just the page. You’d also need to add that custom query to the various functions in the custom loop. That would probably look something like this:

$new_query = new WP_Query([
  'posts_per_page' => 15 // however many posts you want

if ($new_query->have_posts()) :

  while ($new_query->have_posts() && $new_query->current_post < 0): $new_query->the_post(); 
    // do featured post stuff

  while ($new_query->have_posts() && $new_query->current_post < 2): $new_query->the_post();
    // do secondary post stuff

  while ($new_query->have_posts() && $new_query->current_post >= 2): $new_query->the_post();
    // do remaining post stuff


I must be losing my mind. Yes that works. Not sure what I was thinking this morning. Aren’t Monday’s great? :slight_smile:

Thank you

1 Like