Use Two or More Single.php

In WordPress, we can use only one single.php. But sometimes we need different single pages for different categories. Also my friend Hakan needs 2 different single.php for his site. We build a blog page for his Vectorss site but we had a problem with ads and published pictures. We have to change this single pages. After this problem, i was search and found a litte information about this problem. In this information there is a sentence like this “You can solve this problem with if and else“. I think about thisĀ  and i write some function. It’s Worked!With this function/recipe you will change your core single.php file. If you have no information about WordPress coding -so you’re a newbie- you can get some support if you send a mail to me. Don’t touch your single.php if you don’t know about WordPress

Yep, lets start!

We cnahge our core single.php also you have to make a back-up this file. And you have to make 2 copy of this core file, and single-blog.phpsingle-default.php (single-default is a copy of our core file). And upload these 2 files to your host (in template folder). After that, open your single.php on your server (with a ftp program ex: CuteFtp) and clean all code in this file and add this codes to single.php ;

<?php
$post = $wp_query->post;
if ( in_category('3') ) {
 include(TEMPLATEPATH . '/single-blog.php'); }
 else { include(TEMPLATEPATH . '/single-default.php');
}
?>

We make a duplicate with this code. But we give a special command to this code. With If, we said to code “if we click a post in category 3 you have to call single-blog.php to us“. If we get a normal category post, our core single.php call single-default.php to us. After this code our core single.php will be a tunnel page for us.

And if you wanna make more single pages for your different categories you can duplicate this code.

Here is the second code:

<?php
$post = $wp_query->post;
if ( in_category('3') ) {
include(TEMPLATEPATH . '/single-blog.php'); }
elseif ( in_category('15') ) {
include(TEMPLATEPATH . '/single-foto.php'); }
elseif ( in_category('18') ) {
include(TEMPLATEPATH . '/single-video.php'); }
else { include(TEMPLATEPATH . '/single-default.php');
}
?>

Have a nice day!


Related posts:

If you enjoyed this post, make sure you subscribe to my RSS Feed
Comments are closed.
Highslide for Wordpress Plugin