loading
I currently have availability
logo

Hi, I'mKevin Shoffner

Genesis Custom Category Pages

Recently I was doing a project for a client who instead of wanting the default WordPress settings for their Category pages (10 of the recent Posts and displayed based on the most recent Posts).  Instead they wanted all Posts on the same Category page, with the order to be A-Z.  This particular client also used Genesis, so they wanted to learn about Genesis custom Category pages.

Unfortunately there is not a lot of documentation for this type of sorting with WordPress or Genesis framework, and if you are not a programmer this might be hard to do.  Luckily there are resources out there who can assist.  I will try to explain and walk you through the code for the above situation, as well as give you other suggestions for similar types of situations.

 

The first part (i.e., making more than 10 Posts display) is very easy and even the most experienced WordPress users some times forget about.  Once you are in your Dashboard go to
Settings >> Reading and you can change the Blog pages display at most value to whatever you want.  In this case, we are going to change it to 99 just to grab lots and lots (i.e., 99) of Posts at once.

 

Now for the fun part – the programming.  You are going to want to find your functions.php file and add the following piece of code:

/** Order Posts A-Z on Category Pages **/
function be_category_query( $query ) {
if( $query->is_main_query() && $query->is_category() && !is_admin() ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
}
}
add_action( 'pre_get_posts', 'be_category_query' );
/** end of a-z **/

Oh no Kevin, you had me lost at “code.”  No worries, I am going to explain each line of code for you so don’t freak out just yet.

 

/** Order Posts A-Z on Category Pages **/

> This is just a comment area to remind yourself what this cool function

function be_category_query( $query ) {

> we are naming and defining the function here. You can name the function whatever, but I’ve named this function “be_category_query” because I wanted to give a shout out to Bill Erickson, who you will find more information about later in this tutorial.

if( $query->is_main_query() && $query->is_category() && !is_admin() ) {

> queries (finds) all category items, except  don’t look during the time you are in the WP Dashboard.  Speeds up performance

$query->set( 'orderby', 'title' );

> now we finally tell the query to sort by the title of each Post

$query->set( 'order', 'ASC' );

> and then after getting all of the titles in order, we want to sort Ascendingly

}
}

>these just close off of the function

add_action( 'pre_get_posts', 'be_category_query' );

> we now create and execute the function “be_category_query”

/** end of a-z **/

> This is just a comment to let you remember you are closing this cool function

 

 

There are additional ways to do other customizations and sorts, and one of the best resources I have found would be Bill Erickson’s website.  Here is a great tutorial on how to Customizing the WordPress Query.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: