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.

WordPress Snippets at CSS-Tricks

Chris at CSS-Tricks has a huge collection of code snippets for PHP, CSS, jQuery, and, lo and behold, WordPress.

Here’s how you might loop through and display posts in a certain category, for example:

<?php query_posts('cat=5'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>

Custom Post Types vs. Categories

In line with a fundamental keep it simple mentality, I’ve been scouring the web to find best practices on when to use Custom Post Types or when to use Categories. Despite my quest for solid, black-and-white answers, I have found none.

My thought at the moment is to use regular posts and categories as much as you can, and only use Custom Post Types when you really feel need to. Again, no science here, just a gut feeling that you’ll be better off at the end of the day. Take my exhibits, for example: While they seem to be a completely different kind of content, they’re actually just posts of category type “Exhibits.” Easy peasy.

You can read about how to keep posts of this category off the frontpage and out of the regular blog stream here.

Remove certain categories from the frontpage

I’m still not convinced that this is how you want to be doing this, but nevertheless the following will exclude posts of category 11 from showing up on the frontpage:

function exclude_category($query) {
	if ($query->is_home){
		$query->set('cat','-11');
		}
	return $query;
	}

add_filter ('pre_get_posts', 'exclude_category');

Paste the code into your theme’s functions.php.