One of the built-in features of Genesis when editing a category in the WP backend is the Category Archive Settings consisting of category archive headline and intro text fields. If one of these is populated, it/they will appear above the list of Posts in category archives. In this article I share the code to show a subcategories dropdown to the right with which visitors can filter the Posts in category pages.
We shall use the code shared by Bill Erickson which automatically uses Category title and shows it if a custom Archive Headline has not been entered. Below that, Archive Intro Text will be shown. On the right side, if the current category archive page has child categories, they will be shown in the dropdown. Selecting a sub category will work as expected: take the user to that particular category's archive. When on a category page that does not have any sub categories, the dropdown will not appear.
Step 1
Add the following in child theme's functions.php sans the opening PHP tag:
<?php | |
/** | |
* Default Category Title | |
* | |
* @author Bill Erickson | |
* @url http://www.billerickson.net/default-category-and-tag-titles | |
* | |
* @param string $headline | |
* @param object $term | |
* @return string $headline | |
*/ | |
function be_default_category_title( $headline, $term ) { | |
if( ( is_category() || is_tag() || is_tax() ) && empty( $headline ) ) | |
$headline = $term->name; | |
return $headline; | |
} | |
add_filter( 'genesis_term_meta_headline', 'be_default_category_title', 10, 2 ); |
Step 2
Create a file named category.php in your child theme directory having the following:
To view the full content, please sign up for the membership.
Already a member? Log in below or here.
Is it possible to change how the text is displayed when the dropdown is hidden? This results in a half-filled widget with an odd blank space to the right on subcategories. You can see what I mean here: https://demos.cheerfulthemes.com/camille/category/theme-features/ – if you choose a subcategory, then it shows the info with a large blank space where the dropdown would be if it wasn’t empty.