Changing the Genesis Archive Page Settings for Custom Post Types

By default all archive pages and types in Genesis share the same archive settings as set in the Genesis > Theme Settings > Content Archives section, but you can change these settings for a specific custom post type archive and leave the defaults intact for the regular archive pages.

genesis-archive-setting-custom-post-type

 

Looking at the Content Archives in Theme Settings you can discover the field setting name by inspecting the element on each field which will give you the option name or key.  So the below covers the fields that we see in the theme settings…

  • Display = content_archive
  • Limit content to = content_archive_limit
  • Featured Image = archive_thumbnail
  • Featured Image size =image_size
  • Featured Image alignment = image_aligment
  • Entry Pagination = posts_nav

These keys have values which are either a set of defined values in a dropdown list, an integer value or an on/off checkbox, Genesis provides a filter which allows us to change the value, it is called genesis_pre_get_option_{$key}.

This is from genesis/lib/functions/options.php file…

 //* Allow child theme to short-circuit this function
 $pre = apply_filters( "genesis_pre_get_option_{$key}", null, $setting );
 if ( null !== $pre ) {
 return $pre;
 }

The {key} takes on the themes value such as ‘content_archive‘ for example…

genesis_pre_get_option_content_archive

So we can use this filter to alter the custom post type archive settings by a conditional (this example uses the CPT testimonial) whilst leaving the default archive settings intact.

You can either add these to your functions.php or make a plugin, if a setting is not used on the Custom Post Type then it will inherit the default content archive setting from the regular theme setting.

The code can be tidied up a bit if you are going to alter a lot of the options, you can bundle all the options into one conditional and use a hook to fire it, the genesis_before_loop is used in this example below.

Even better is to create an archive template for that CPT and just add the filters straight in that…

Page Layout and Breadcrumbs

A couple of other Genesis theme settings that you are more likely to change for your Custom Post Type Archives are page layouts and breadcrumbs that are also in the Genesis theme settings.

Breadcrumbs

Breadcrumbs has  checkbox options on/off, one for archive and one for single posts…

  • breadcrumb_single
  • breadcrumb_archive

Page Layout

Page layout has 1 option/key …

  • site_layout

With 6 possible values

  • full-width-content
  • content-sidebar
  • sidebar-content
  • content-sidebar-sidebar
  • sidebar-content-sidebar
  • sidebar-sidebar-content

Both of these can be used with an inline function instead of creating a separate function – since the breadcrumbs is a boolean value; either true/false it can use the WordPress  __return_true function and Genesis comes with site layout inline functions for the corresponding layout…

  • __genesis_return_full_width_content
  • __genesis_return_content_sidebar 
  • __genesis_return_sidebar_content
  • __genesis_return_content_sidebar_sidebar 
  • __genesis_return_sidebar_content_sidebar
  • __genesis_return_sidebar_sidebar_content

So they can also be used in the archive template
(For the setting for breadcrumbs on the single CPT posts, you would either create a single CPT template and add it or via the functions.php as illustrated previously)

Also handy are a couple of WordPress filters to control post excerpt and post display

Controlling Post Excerpts

Apart from showing the full content and content limitation using, you can show the excerpts instead and you can control the excerpt amount (normally 55 words) using the WordPress filter excerpt_length

Controlling Amount of Posts to Display

To set a specific amount of posts to display without changing the core blog posts amount and just changing for the CPT archive you can use the action pre_get_posts with a couple of conditionals to target the front end, main WP query and CPT.

That’s it – I tend to find that making archive templates is an easier and cleaner approach and just adding the custom settings in.

Leave all Comment