All posts on your WordPress site will be published using the single.php template. The single.php file is used when you click on the post title on the Home Page or Archive Page of the site, and you will see just the single post.

In WordPress, we can use only one single.php. But sometimes we need different single pages for different categories, where you want the single post page to look different.

&nbsp:

Question is how to do that?

You can solve this problem with conditional statement.

First, you have to note down the category ID.

Second, copy your signle.php and rename it single-photo.php, single-video.php and single-default.php.

Now you have 4 single.php files in your theme folder.

Open your single.php and delete all codes inside the file and put this code below:

<?php

$post = $wp_query->post;

if ( in_category(‘3′) ) {
include(TEMPLATEPATH . ‘/single-photo.php’);
} elseif ( in_category(‘4′) ) {
include(TEMPLATEPATH . ‘/single-video.php’);
} else {
include(TEMPLATEPATH . ‘/single-default.php’);
}
?>

Upload to your server all the single.php files and see the change…

That’s all.

Categories: Tutorials, Wordpress

About

He is a freelance graphic designer with more than 15 years of design experience, including both print and web design.

.. Write a Guest Post ..


2 Responses so far.


  1. nigel says:

    nice tutorial…..

  2. Jerick says:

    Wow… thanks for this tutorial… this helps me a lot..!

Copyright © 2017 gopalbonline.com