I've been away from Wordpress for a few months, and now I'm struggling to remember how to create a Page of Posts. It's most infuriating!
The Current Site
I have home.php
set up to display the latest Posts of a Custom Post Type as the main page. It works fine. A simple pre_get_posts
function in functions.php
sets the CPT to be displayed:
$query->set('post_type', 'campaign');
$query->set('posts_per_page', 11);
...when is_home() && $query->is_main_query()
. This is correct, and does not need to be changed. It works great, but now the client wants a normal news blog elsewhere on the site.
The New Version
So... I need to add a news blog, that's not on the homepage, leaving the homepage as it is. It makes sense to me to use the default Post post type for this, and it makes sense for me to create a Page for this. But I can't seem to get a Page of Posts to work.
At first I created a page-blog.php
template for a "News" Page, but it didn't pull in Posts with while ( have_posts() ) : the_post();
. Instead it only listed itself...?
I then added a new line to my pre_get_posts
function:
if(is_page_template('page-news.php')) {
$query->set('post_type', 'post');
}
But now the page returns 404.
What am I doing wrong?