WordPress Attachment Category/Terms

Posted on 2011/02/22 Comments

I was working on a photography site project for a dear friend of mine, Virda, and it requires me to set categories/terms for the attachment images. By default, an attachment post will inherit its parent terms, but, what if we only need to pull attachments which have certain terms? Querying their parents and then filtering the result will surely need more time and resources don’t you think? Besides, we won’t have the freedom to set the attachments’ terms without modifying their parent posts.
Continue…

Add Custom Class(es) to ANY Widget

Posted on 2010/11/21 Comments

WordPress has a powerful API for creating, configuring and displaying widgets, but one thing I really need is the ability to add custom class(es) to the widgets. Every widget should usually come with its own classname, which will be printed when the sidebar is being displayed. So, assuming you’ve used the correct method for registering sidebar, you can add these following functions to your theme/plugin to provide the user the ability to add custom class(es) to the widgets.
Continue…

KC Settings

Posted on 2010/10/25 Comments

I’ve been writing WordPress themes for these past two years. Some of them are very simple and some others are quite complex. These themes need a settings panel so the user (or the site admin) can configure their site comfortably. There are many methods around the interwebs on how you can create such a settings panel for your theme/plugin. I tried to adapt some of them into my themes, but there was always something wishpering in my ear telling me to write my own settings panel with my own way :) .
Continue…

Add Custom Attributes to WordPress’ Posts Navigation

Posted on 2010/08/28 Comments

The Problem

We need to add our custom class(es) to the posts navigation links to be able to add some styles.

The Solution

Use the available next_posts_link_attributes and previous_posts_link_attributes hooks.

How?

Open your theme’s function.php file and add these lines (must be inside the <?php ?> tag):

add_filter( 'next_posts_link_attributes', 'kc_next_post_link_attr' );
add_filter( 'previous_posts_link_attributes', 'kc_prev_post_link_attr' );

function kc_next_post_link_attr() {
	return 'class="next-page"';
}

function kc_prev_post_link_attr() {
	return 'class="prev-page"';
}