Posts Tagged: WordPress

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.
	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){
	return $query;

add_filter ('pre_get_posts', 'exclude_category');

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