How to show a post single post in page template

The question:

Currently I’ve divided posts into 5 different categories, based on the categories I’ve created 5 page templates. all of the pages are listed into the home page navigation menu. in my home page I’m showing 5 posts in five different categories. when they clicked a post that post will shown in the single page template(that’s what word press normally does) but i want to show that post into my page template. because each page template having different designs. if there is any way to set the permalink to point to the page template and show the post in to full.

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

The »Template Hierarchy« doesn’t allow this per default.

Inside your single.php template, you can call load_template().

This will allow you to simply include the template you need, based on the in_category() conditional tag.

// inside single.php
if ( in_category( 'foo' ) )
{
    load_template( get_stylesheet_directory().'foo_template.php' );
} 
elseif ( in_category( 'bar' ) )
{
    load_template( get_stylesheet_directory().'bar_template.php' );
} 
elseif ( in_category( 'whatever' ) )
{
    // ...
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment