My current singlepost.php makes use of the following if conditions and renders the appropriate template.
<?php
$post = $wp_query->post;
if ( in_category('4') || in_category('59') ) {
include(TEMPLATEPATH . '/review-post.php');
}
elseif (in_category('5')) {
include(TEMPLATEPATH . '/promo-post.php');
}
else {
include(TEMPLATEPATH . '/regular-post.php');
}
?>
I want to modify this such that /123-author.php single post template is rendered when a post is published by a particular author.
How can I modify/append to the above conditions so that the single post would look for a particular template whenever it notices a post made by 123author?
Thanks.
I’m making a couple of assumptions about how your theme is setup:
For example purposes, I have two users in my system each of which are identified by ‘admin’ and ‘user.’
At this point, we’ll create a second template for displaying content by a certain author. In the root of your theme’s directory, add a new template file – this file will be used to render content for a specific author.
Assuming that your basic template file is
content.php,
addcontent-user.php.
You can add whatever you want to this file – a good place to start may be copy and pasting the content fromcontent.php.
Note that the name of the new template doesn’t matter, but it’s a bit clearer since it’s going to render content by author named ‘user.’Next, hop into your
index.php
file and locate the loop. Odds are it looks something like this:If your theme doesn’t support post formats and/or you’re using standard include files as you mentioned above, it may look like this:
For purposes of this answer, I’m going to go with the first example. That’s the best practice for including different template files into your content.
At this point, we need to setup a check to include the template based on the user. I’m going to setup my loop display a template for all articles written by ‘user’ and display a separate template for all articles written by ‘admin’ and anyone else:
The code should read easy enough, but to be clear:
Your mileage may vary based on your theme is setup but taking advantage of the get_the_author() function should help you in dynamically selecting a template.
Update Based on Answer Comment
You can use get_the_author_meta.
Without seeing more of your code, I can’t be certain how your theme is setup, but if I had to guess based on the code you provided, I’d suggest trying something like this:
Sometime we needed to show our details page (that means single.php) in different styles. For this sense, I write a post on http://www.webinbangla.com/2012/05/different-style-of-single-php/