Graphic & Web design blog

10 useful WordPress theme hacks

WordPress theming has become a important revenue source for many freelance developers and web designers, which is a pretty good reason to constantly improve your skills in that field. The following WordPress hacks teach you how to do some commonly wanted theming features.

1. Exclude a category from the homepage

Sometimes you will not want a category’s posts to appear on the homepage, for example if you want to use a category to display notes in your sidebar. In that case, this is the code you should in your loop (the bold line is the one excluding category number 7).

2. Exclude a category from the RSS feed

For pretty much the same reason, you could want to prevent a category to be included in the RSS feed. For that you don’t even need to tweak your template files, you just need to append a query string to the feed URL, like in the following example.

http://www.designer-daily.com/feed?cat=-7

3. Displaying posts from one category in the sidebar

Well, since the reason I gave to exclude categories from the homepage is to display that category as sidenotes, I’ll show you how to do that part too. Of course you could use a plugin or a RSS widget (with the category’s feed) for that, but here is how I would do it.

5. Styling featured posts

The ability of creating featured posts in WordPress has been made much easier with the 2.7 version, in fact a little “stick this post to the front page” has appeared in that version. All you need to do is to hit the checkbox and make sure that you have a class set for your post with this line.

<div <?php post_class() ?> id="post-<?php the_ID(); ?>">

Then you can use the .sticky class to change the properties of the sticky posts, for example to make the text white on a black background you would put this in your stylesheet.

.sticky {color:#fff;background:#000;}

6. Exluding specific pages from a page list

You’ll have to know this one to create navigation menus, it’s actually quite simple to do. Just insert this bit of code.

<?php wp_list_pages('exclude=12' ); ?>

7. Create a page-specific template

This is also quite simple, first you have to create a new page template file, like in this picture.

On the very top of this template file, you must add this code.

<?php /* Template Name: Example page template */ ?>

Then make all the changes in the core of the template, add/remove sidebars or do whatever you want. When editing your page in WordPress admin you should see this option in the Attributes box.

Please note: Sometimes it’s necessary to switch to the WordPress Default Theme, then back to your theme, for the Template choices to appear.

8. Highlight author comments

This is useful to make the author comments pop in the comment section, so the readers find the answers to their questions quicker. It can also avoid people pretending they are the author by commenting with his name. To style the author’s comments differently, you should open the comments.php template file and look for this piece of code (or something looking like it).

10. Add a print button to your blog’s articles

So you spent hours creating a specific stylesheet for people wanting to print your articles but nobody is printing them? Suggest them to print by adding a little print link or button, it’s easy, just insert this bit of code where you want the link to appear.

About this site

Designer Daily is a place for designers to find inspiration, resources, and thoughts that will be useful to their daily work. It is maintained by Mirko Humbert, a Swiss graphic and web designer who is available for freelance work. More info.