Dec 172008
Part of the Wonderful WordPress Wednesdays Series - Previous in series         Next in series

Welcome to the ninth installment of my Wonderful WordPress Wednesday series.

NOTE: Although the main focus of this week’s tutorial is sponsored blog posts, there are many, many uses for what I’ll be sharing with y’all today so don’t run off just yet. After the tutorial I’ll share some other great uses for today’s lesson.

Anyone who has ever taken a sponsored post through any of the ‘paid to blog’ companies knows that they’re all full of various rules restricting how you can lay out your blog. Anyone who has taken sponsored posts for more than a few months has no doubt run into frustrations at what seems to be the usurping of your blog by these companies. Well, I’ve finally found a simple and elegant solution – separate templates for individual blog posts.

To see what I mean click over to my latest post at Gilroy Review about how columnist Cynthia Walker hates poor people.  Scroll down and take a look at the entire layout of that post.  Then click on the navigation to go to the post before it on Mary Jane Goods.  Notice anything different?  The ad placements are totally different because one is a sponsored post while the other is not. (BTW, if you’re reading this Google, the sponsored links are all nofollowed so don’t get your servers in a bunch).

All I had to do to accomplish those entirely different post layouts was tell my blog that a different author wrote each post.  I use author because I’m the only person writing on these blogs and my blog themes don’t mention author names anyway.  I could do the same thing with a specific tag or category as well.  I only use author because it’s completely transparent on my blogs.  Now, this did take a little set-up which is what I’m going to layout for y’all here in this post.

I learned how to do this, BTW, thanks to a great post by Justin Tadlock on his terrific Life, Blogging & WordPress blog.  That post contains a lot of code because it covers so many options, and all of that code can be pretty intimidating to people who aren’t used to messing about ‘under the hood’ of their WordPress installation.  So I’m going to stick to one simple system here.  If you want to change templates based on something besides the author of the post then please visit Justin’s site and you should be able to follow along just fine after seeing how easy it is here.

How It’s Done-

Enough blathering.  On to the tutorial itself…

First you’ll need to visit Appearance > Editor within your WordPress Admin and select your Single Post (single.php) file.  Select the everything in the text box there (either drag your cursor over all of it or simply click in the box and hit CTRL-A) and then paste it into your favorite text editor.  Personally I use EditPad, but Notepad works just as well in this case and is available on every Windows computer.

This is the basic template file that determines the layout of the single post pages on your blog. It’s probably already setup in an ‘advertiser friendly’ manner so you’re going to leave this copy alone.

Now return to your WordPress admin, go to Users > Add New and make a new user that you’ll only use for your sponsored posts (or whatever pots you want to use the old template for).  By the way, if you want the author to display the same as your current account on your blog just include the same name in the Nickname box and select that name in the “Display name publicly as” drop down menu.  Ok, once that user is made click on them to go to their edit page and look at the URL in your address bar.  Roughly in the middle you should see something along the lines of "?user_id=4". That number is the key to our next step. Return to your text editor program and save the file as single-author-?.php, replacing the ? with the number you saw in the URL above. Pretty easy so far, right?

Okay, now you just need to open your FTP program and connect to your server. Navigate to Your Blog > wp-content > themes > Your Theme and make a new folder or directory there called single. Then upload your newly saved file to that folder/directory. It should end up looking something like my FTP directory to the right.

That was the hardest part, I promise.  Now you just need to return to your WordPress admin area again and go to Appearance > Editor but this time select Theme Functions (functions.php). Each of these is going to look a little bit different depending on what theme you’re using, but you don’t need to worry about that. Just scroll down to the very bottom where you’ll see ?> and place your cursor on the blank line above that one. Then paste the following into the file and hit Update File-

* Define a constant path to our single template folder
define(SINGLE_PATH, TEMPLATEPATH . '/single');

* Filter the single_template with our custom function
add_filter('single_template', 'my_single_template');

* Single template function which will choose our template
function my_single_template($single) {
	global $wp_query, $post;

	* Checks for single template by author
	* Check by user nicename and ID
	$curauth = get_userdata($wp_query->post->post_author);

	if(file_exists(SINGLE_PATH . '/single-author-' . $curauth->user_nicename . '.php'))
		return SINGLE_PATH . '/single-author-' . $curauth->user_nicename . '.php';

	elseif(file_exists(SINGLE_PATH . '/single-author-' . $curauth->ID . '.php'))
		return SINGLE_PATH  . '/single-author-' . $curauth->ID . '.php';

	* Checks for default single post files within the single folder
	if(file_exists(SINGLE_PATH . '/single.php'))
		return SINGLE_PATH . '/single.php';

	elseif(file_exists(SINGLE_PATH . '/default.php'))
		return SINGLE_PATH . '/default.php';

	return $single;


Now just go back to your Single Post (single.php) file and make whatever changes you want to your single post layout – ad layouts, styles, backgrounds, etc – without having to worry about the opinions of the sponsored blog companies you work for. Just make sure to select that other (fictitious) author whenever you do a paid post and theirs will appear on a page that meets all of their requirements.

Personally, I also plan on using this when setting up a Daddy-Daughter blog with Zaira in the near future to give my posts a black & white color scheme and hers a pink & black scheme. This system would also be perfect for when you have guest bloggers and it can also be used to differentiate between categories or subjects on your blog rather easily. For example, if you have a weekly photo feature as many do, or host a blog carnival you could use an entirely different template for those posts. As I mentioned above, if you want to differentiate by category or tag just visit  Justin Tadlock’s original post on the concept at his Life, Blogging & WordPress.

I’m sure there are plenty of other uses for this as well, so if you’ve got any ideas, please leave a comment and let me know!  Or, if you have any questions or problems, just leave a note and, as always, I’l ldo my best to help.!

Part of the Wonderful WordPress Wednesdays Series - Previous in series        Next in series

  14 Responses to “Stop Letting Sponsors Determine Your Blog Layout!”

  1. Glad you found it useful Holly! Once I figured out what I needed to do it took me less than 20 minutes to apply this to each of my blogs.

  2. Thanx, Heather!

    In rereading this post I realized I actually made it sound more difficult than it is. The whole “copy and paste your single.php file isn’t even really necessary. You can simply download it via FTP, rename it, then upload it to the new folder.

  3. […] presents Stop Letting Sponsors Determine Your Blog Layout! posted at Philaahzophy, saying, “Ever wanted to use different templates for posts by […]

  4. Glad you liked it, JMom!

    I totally forgot to mention something for my fellow Posties – after you’ve been paid for a post (ie. when your 30 day commitment is up) you can easily go back and change the author (or whatever signifier you used) back to your non-sponsored one and the template will change back to your preferred display method.

  5. Welcome John!

    I’m Aahz and I do my best to keep Philaahzophy as informative and welcoming as possible. I hope you’ve found something useful and look forward to hearing from you again!

  6. Just want to say your article is as astonishing.
    The clarity in your submit is simply nice and i can assume
    you’re an expert on this subject. Fine together with your permission let me to seize your feed to stay up to date with imminent post.
    Thank you one million and please keep up the enjoyable work.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>