Creating custom post-listing templates in twentyseventeen child theme

Question

I’m using a child theme based on ‘Twenty Seventeen’ and have created a custom post type (‘review’).

I want to make two Pages, one which lists ‘reviews’ and the other which lists a mixture of ‘posts’ and ‘reviews’ (ordered by recency).

For the first of those I’ve made a copy of Twenty Seventeen’s index.php, as page-reviews.php, and added code like this at the start:

$args = array(
    'post_type' => 'review',
    'orderby' => 'date',
    'order' => 'DESC',
    'posts_per_page' => 10,
);
$the_query = new WP_Query( $args );

Then, further down, replaced have_posts() and the_post() with $the_query->have_posts() and $the_query->the_post() respectively.

If I choose to use that template for a Page then it works in that the ‘reviews’ are listed, but the layout is all messed up. There are a lot of classes in the <body> which mess up the layout.

For example, the standard blog front page, using index.php, has these classes in its <body> and looks fine:

blog logged-in admin-bar hfeed has-header-image has-sidebar colors-light customize-support

While my custom page has these:

page-template page-template-page-postslist page-template-page-postslist-php page page-id-15071 logged-in admin-bar has-header-image page-two-column colors-light customize-support

How can I make a custom template that acts more like index.php in terms of the classes it adds?

0
, , , Phil Gyford 5 years 2017-02-16T10:53:56-05:00 0 Answers 90 views 0

Leave an answer

Browse
Browse