Post Title Only Category Pages

How to set your Genesis category pages to display just the post titles.

Place the following code snippet into your functions.php file. Located: Dashboard > Appearance > Editor > functions.php

add_action('genesis_before','remove_some_actions');
function remove_some_actions() {

    if ( is_category()) {

        remove_action( 'genesis_before_post_title', 'genesis_post_info' );

        remove_action( 'genesis_after_post_content', 'genesis_post_meta' );

        remove_action( 'genesis_post_content', 'genesis_do_post_content' );

    }    

}  

Looking at the code you can see that it is specifically calling your category page and then removing the post info, post meta, and the finally the content – leaving you with just your titles. Woohoo!

If this didn’t work for you, then there is probably an action in your specific theme that is interfering. A good example of this is the Pixel Happy theme in which the post info and post meta functions have been renamed. Inside of its functions.php file you will see this:

// Restablish the post info line
remove_action('genesis_before_post_content', 'genesis_post_info');
add_action('genesis_before_post_content', 'pixelhappy_post_info');
function pixelhappy_post_info() {
    if(is_page()) return; // don't do post-info on pages
	genesis_post_info();
}

// Restablish the post meta line
remove_action('genesis_after_post_content', 'genesis_post_meta');
add_action('genesis_after_post_content', 'pixelhappy_post_meta');
function pixelhappy_post_meta() {
	if(is_page()) return; // don't do post-meta on pages
	genesis_post_meta();
}

So for our nifty code snippet to work, we would need to rename them as well:

add_action('genesis_before','remove_some_actions'); 

function remove_some_actions() { 

    if ( is_category()) { 

        remove_action( 'genesis_before_post_content', 'pixelhappy_post_info' ); 

        remove_action( 'genesis_after_post_content', 'pixelhappy_post_meta' ); 

        remove_action( 'genesis_post_content', 'genesis_do_post_content' ); 

    }     

}

Now let’s say you want to display only the titles on a specific category or multiple categories. Using the same snippet you can make it happen!

As an example, i’m looking to show just the post titles on my “Genesis Tutorials” category. I can call it a few different ways, by the term_ID “1″, the slug “genesis-tutorials”, or the name “Genesis Tutorials”. If I were using the name I would do the following:

add_action('genesis_before','remove_some_actions');
function remove_some_actions() {

    if ( is_category( 'Genesis Tutorials' )) {

        remove_action( 'genesis_before_post_title', 'genesis_post_info' );

        remove_action( 'genesis_after_post_content', 'genesis_post_meta' );

        remove_action( 'genesis_post_content', 'genesis_do_post_content' );

    }    

}

If I wanted to use the id or slug, I would just change ‘Genesis Tutorials’. In my example, I would change it to either ’1′ or ‘genesis-tutorials’.

Now let’s say I want to show just the post titles on both “Genesis Tutorials” and another category “Code Snippets” and I will call them using their name. I can achieve this by using an array, like so:

add_action('genesis_before','remove_some_actions');
function remove_some_actions() {

    if ( is_category( array( 'Genesis Tutorials', 'Code Snippets' )) {

        remove_action( 'genesis_before_post_title', 'genesis_post_info' );

        remove_action( 'genesis_after_post_content', 'genesis_post_meta' );

        remove_action( 'genesis_post_content', 'genesis_do_post_content' );

    }    

}

You could also easily tweak this function to remove, say – only the post content, leaving you with a category page with just the post titles, post info, and post meta.

Hope that helps out! There’s a lot you can do with WordPress and Genesis by using conditional tags.

Comments

  1. Joan says:

    Hi! Thanks for your article, very helpful!

    I was wondering if it’s better use that conditional if on the functions.php, or if it’s better create a category.php template file with the remove actions and the genesis() call. Is there any difference?

    • Justin Twerdy says:

      Just personal preference as there’s not going to be a noticeable performance gain from PHP organization. A time to separate them would be if your functions.php started bursting at the seams making it hard to manage. You could also create a folder with your various functions files and then include them within functions.php. Another thing to note (that is often overlooked) – creating a Functionality Plugin for all that code that shouldn’t be in there in the first place (: Personally, with Genesis I can usually keep my functions.php file pretty small – way I see it, if i’m only going to be making a few changes to (say the category page) it just doesn’t make sense to me to duplicate that file just to make my one or two changes.

      • Joan says:

        So, it’s just a question of organization, no PHP performance. I guess it depends on how large the final functions.php is. Great to know. I’ll check the Bill Erickson Functionality Plugin too.

        Thanks so much!

Speak Your Mind

*