0

I'm searching for the best solution to create custom layouts for blog pages in WordPress.

Where you would normally select a custom page template from the Template metabox in admin to change the page layout, this does not work for static blog pages.

By default, WordPress template hierarchy is looking for home.php and then index.php to display, it does not check for custom page templates at all. View the Template Hierarchy here. WordPress codex also notes this about Blog pages:

Do not use a custom Page template for this page. The template files home.php or index.php will be used to generate this page in the Theme.

I personally find this very odd. If there is one page I would like to have different layouts available it's the blog listing.

My current and only solution is to create a new metabox called something like "Blog Layouts". My home.php then loads a custom template part based on what value is set by the metabox. Although I'm sure this will work, It feels kind of hacky knowing that WordPress provides it's own metabox for setting page templates.

If anyone has better suggestions, I'm really happy to read them.

  • You can create a custom page template, create a page and assing the custom template to this page. Then, in WordPress settings->reading set that page for the front-end. Where is the problem? – cybmeta Feb 10 '15 at 17:28
  • @cybmeta Doesn't work because of what I've written above, you can try it yourself if you don't believe me. Read this for clarification: chipbennett.net/2013/09/14/… – piggypig Feb 10 '15 at 17:32
  • It works. I repeat with missed information: create a page and assing the custom template to this page. Then, in WordPress settings->reading set that page for front-end as Static home page. In the custom page template you can do whatever you want, including building a blog index; also, you can use pre_get_posts action to alter the query for that custom page template. – cybmeta Feb 10 '15 at 17:51
1

If you wrote in a conditional on the home.php or index.php couldn't you loop through with get_template_part(); ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.