I want to create a new custom page template for the presentation of blog posts. I realise that when you assign a page to display posts via Settings > Reading, it then will assign home.php to display that page content – being posts on a page. Also the option to assign a page template in the page editing view disappears.
Right now it displays a default article by article view. I want to provide another option for admin to select a different template which could style the blogs in a gird or masonry layout. I’m not sure how to do this.
I could do it by not assigning the page to display blogs in the Settings > Reading admin area and then allowing admin user to assign the specific template to page using Page Attributes menu in page editing but according to https://make.wordpress.org/themes/2014/06/28/correct-handling-of-static-front-page-and-custom-blog-posts-index-template/, this is the WRONG way.
I’ve tried google searching for solutions but all I keep finding is recommendations for plugins to use. Could someone point me to some helpful resources?
Don’t forget that WordPress was primarily designed to be a blogging CMS, so when it comes to theme development, developers often opt for a non-standard approach in exchange for the potential for more features.
Theme developers have three options when they approach this, one of which (#2 below) you mentioned.
-
Directly edit the
index.php
to modify the blog index. This is not a good option becauseindex.php
should be the a fallback in case another part of your template is missing.- Pros: fast and easy
- Cons: error prone and against object oriented principles
-
Create a page template for the blog index. Like you said, many theme developers elect to go this route because it’s a fast way to give you control over the blog index, and it actually gives you the ability to play around with different blog index templates (which is useful when developing a versatile theme).
- Pros: Versatile, allows for building a robust theme
- Cons: you lose the ability to call WordPress’ native functionality that pertains to the blog index.
-
Create a
front-page.php
,home.php
andindex.php
in your theme. Thefront-page
will be the home page for the theme.home
will default to your blog index andindex
will be your fallback for all templates.- Pros: Clean and makes full use of WordPress’ native objects and methods
- Cons: Limited by WordPress: not ideal for many of the kinds of option-rich themes you see today
Personally I like to go with #2, because most of my WordPress development projects these days are not just blogs: they’re entire sites with deep information architecture and complex interactivity.