I wouldn’t use custom page templates merely for changing the layout of the blog posts index. Using page templates for the blog posts index bypasses the core handling for display of the blog posts index (which per the template hierarchy uses either home.php
or index.php
to render).
Edit
I never…said that I want to change layout of the blog posts ‘index’ in my question.
Yes, that’s exactly what you’re talking about. In WordPress nomenclature, the blog posts index is the default listing of all blog posts, whether on the site front page, or a static page. When you configure Settings -> Reading -> Front Page Displays
as a static page
, and then assign a static page to Posts page
, then WordPress uses that assigned static page to display the blog posts index.
When WordPress uses that page to display the blog posts index, it ignores any assigned page templates. It ignores the page.php
template. It always and only uses either home.php
or index.php
.
Thus, if you force the user to use a custom page template to display the blog posts index, then you’re breaking the way that core functionality works. In order for users to be able to use your custom page templates, they have to create yet another static page, and then assign your custom page template to that page. The users either have to unassign the page assigned to Posts page
in Settings -> Reading
, or simply ignore that the page exists, and duplicate its output on the separate static page to which they have assigned your custom page template.
Original Solution
Instead, define a Theme option for blog layout, then use that option value to conditionally include template-part files, conditionally display sidebars, or to filter body_class
(or post_class
) for CSS changes.
Conditional Template-Part Files
$theme_options = get_option( $option_name );
get_template_part( 'content', $theme_options['blog_layout'] );
Conditional Sidebars
$theme_options = get_option( $option_name );
if ( 'full' != $theme_options['blog_layout'] ) {
get_sidebar();
}
Filter body_class
function wpse141248_filter_body_class( $classes ) {
if ( is_home() ) {
$theme_options = get_option( $option_name );
$classes[] = 'layout-' . $theme_options['blog_layout'];
}
return $classes;
}
add_filter( 'body_class', 'wpse141248_filter_body_class' );
Filtering post_class
would be essentially the same technique.