Theme individual Posts in WordPress

In Drupal, theming each node (post) individually was an out-of-the-box feature. Unless I’m missing something, WordPress doesn’t have this functionality yet. Luckly, Justin Tadlock has a perfect solution. You can go through the steps there, but it basically involves including a function in functions.php that checks for a single-post_ID.php file in your theme folder. If you want to completely change the function and form of post #341, just create single-341.php file and theme it as you would a normal single.php file.

For a several examples of why you would want to do this, just visit Jason Santa Maria’s site—it’s brim-full with individually styled posts. Though his website looks to be hand-crafted, it’s easy to do in WordPress now too.

Posts in draft stay in draft

Most CMSs these days have a draft option for posts. You come up with an idea, scribble down a few lines to outline your thoughts, and save the post as a draft. Ideally, in a day or so you’ll come back to flesh out your ideas, maybe add a few more, and through some magical and deeply satisfying process, you’ll press Publish on a thoughtful, meaningful, multi-paragraph piece of work.

But you know that never happens. What actually happens is that you keep making drafts, and soon you’ve got so many draft posts that you need to filter those out to make the list of posts more readable. Eventually, on some dark and stormy night at home on the couch, in a fit of organizational rage, you’ll delete them. And happy you will feel for fleeting moments. But then you’ll lament their loss. Then you’re back making drafts again to replace the feeling of grief and dispair in this brutal and endless cycle of incompletion.

Apologies if you were reading to the end for a solution. There isn’t one to be found here. Perhaps the first step towards a smaller pile of draft posts, though, is recognition: Posts in draft stay in draft.

The world will be a better place after reading about that burning idea in your head—take the time to be able to hit Publish instead of Save Draft.

Add a byline to your posts

Every good post needs a good byline (the purple sub-heading above). With WordPress, it’s easy to setup:

1. First things first, you need make a new custom field. This is right at the bottom of the Add New Post page.

2. Next, add a little piece of code to the loop sections of the appropriate files in your theme (single.php, index.php, single.php, page.php, etc). Be sure to place this right before the $the_content() function.

	<?php if ( get_post_meta($post->ID, 'Byline', true) ) : ?>
      <div> <?php echo get_post_meta($post->ID, 'Byline', true) ?></div>
    <?php endif; ?>
	

This tells WordPress to look for a byline before printing out the rest of the content in your post.

3. Last, a little bit of CSS to make things look right and you’re all set.

.byline {
	font-size: 13px;
	font-style: italic;
	color: #CB1C9E;
	margin-bottom: 25px;
	}

This technique will work for any kind of custom content—just replace the word ‘byline’ in the function above, with the name of your custom field.

Add a link to the Dashboard

I’m always switching back and forth between my site and the Dashboard. To make it easier to get back and forth, I’ve got admin links placed all over the place. Just paste this code in your sidebar.php, footer.php, your main page loop or anywhere else you want it to appear.
<?php
	if ( is_user_logged_in() ) {
		echo '<a href="wp-admin">admin</a>';
		} else {
		echo '';
	};
?>

This is basically telling WordPress to show the link to wp-admin, if you’re logged in and to show nothing if you’re not.

A Category for all seasons

You’ll notice that this site has a few different sections or categories of content. The main frontpage blog posts, the (Rolling Stone quality) Ryan Adams reviews, seasonal exhibits, etc… Of course you don’t want to have them all look the same, and of course you don’t have to.

As per the Codex page, this is a pretty easy thing to do. My exhibits category, for example, simply has a new template file: category-exhibits.php. Similarly, Ryan Adams gets his own file too: category-ryan-adams.php.

After you’ve made a new template file, just copy the contents one of your other templates (index.php or page.php) and make changes as you need to. WordPress happily takes care of the rest.