In this tutorial we’ll take a look at the built in Genesis settings you can use to control the content limits in your archives and blog page template.
We’ll also take into consideration the WordPress reading settings and how they effect the Genesis settings.
On top of this, we’ll also look at some working code snippets you can use to further customize your:
- Blog Page
- Archives
- Home page
- Grid loop
- Custom Post Types
We’ll use the new Eleven40 Pro child theme by StudioPress as well as the Genesis 2.0 Sample child theme which doesn’t include any grid loop or home page widgets out of the box.
The Eleven40 Pro theme along with several other StudioPress themes like the Balance theme include a custom grid loop in the home.php file.
Reading Settings in WordPress
Firstly, lets look at the existing settings WordPress provides in the Reading Settings. These settings will effect how many posts display on all your archive pages including:
- Blog listings page
- Archive pages including author, blog, category, search, and tag pages
The reading settings determine how many posts are displayed on all your archives pages and home page if left at the default settings like you see in the above screen shot.
The Reading Settings do NOT control your blog page as this is controlled by the Blog Page Template settings Genesis includes under the Genesis > Theme settings:
Lets look at an example of this: If your Reading Settings are set to display 5 posts, your home page and all archives will display 5 posts however your blog page will display whatever you set it to display.
Even though the Reading settings might be set to: Blog pages show at most 5, this only applies to the home page and NOT when using a static custom page with the blog page template for your custom blog page.
These settings are controlled by the genesis blog page template settings as shown in the screenshot above.
Customizing Default Home Page Post Limit
If you want your archives to display the number set in the Reading Settings but display a different number of posts on your home page, you will need to use some custom code in your child themes functions.php file:
add_action( 'pre_get_posts', 'change_posts_number_home_page' ); function change_posts_number_home_page( $query ) { if ($query->is_home() && $query->is_main_query() ) { $query->set( 'posts_per_page', 5 ); return $query; } }
The above code won’t effect the number of posts displayed on your archives.
Change Number Of Posts Displayed On Archives
You can also use this code to change how many posts display on different archives like category and author archive pages without effecting the Reading Settings which control the others:
add_action( 'pre_get_posts', 'change_number_posts_per_category' ); function change_number_posts_per_category( $query ) { if ( is_category('29') ) { $query->set( 'posts_per_page', 1 ); return $query; }}
Customizing Grid Loop Post Limit On Home Page
If your theme includes a grid loop in the home.php file, you can simply control how many full width featured posts and how many grid loop posts are display on your home page.
On top of this, you can also control the content limit for both featured posts and posts displayed in the grid only on the home page as the code is included in the home.php file.
All the settings are in the home.php file grid loop code:
remove_action( 'genesis_loop', 'genesis_do_loop' ); add_action( 'genesis_loop', 'eleven40_grid_loop_helper' ); /** Add support for Genesis Grid Loop */ function eleven40_grid_loop_helper() { if ( function_exists( 'genesis_grid_loop' ) ) { genesis_grid_loop( array( 'features' => 1, 'feature_image_size' => 0, 'feature_image_class' => 'alignleft post-image', 'feature_content_limit' => 0, 'grid_image_size' => 'grid-featured', 'grid_image_class' => 'grid-featured', 'grid_content_limit' => 250, 'more' => __( '[Continue reading]', 'eleven40' ), 'posts_per_page' => 5, ) ); } else { genesis_standard_loop(); } } genesis();
The PHP code above is set to display 5 posts. Starting with one featured post which displays full content width and unlimited content limit as its set to 0 so it displays the full post content of the first post.
It then displays 4 posts in a grid with each set at a content limit of 250 with featured image if you have uploaded one for each post and set it as a featured image.
These settings are overwritten by the Reading Settings meaning if your Reading Settings are set to display 20 posts, that’s what your home page will display regardless of the settings in the above grid loop.
To customize this, you can use this PHP code below in your child themes functions.php file to overwrite your Reading settings for your grid loop and therefore use the Readings Settings to control how many posts are displayed on all your archive pages.
Change Grid Loop Posts Limit
add_action( 'pre_get_posts', 'change_num_posts_in_grid' ); function change_num_posts_in_grid( $query ) { global $wp_the_query; if( $query->is_main_query() && is_home() ) { $query->set( 'posts_per_page', '5' ); } }
The above code can also be modified to work on any other pages using the grid loop simply by changing the conditional tag in the code from is_home() to something else.
Sub Pages of Home Page
If you also want to control the number of posts displayed on sub pages for grid or standard excerpts, you can use code like this:
add_action( 'pre_get_posts', 'change_num_posts_in_grid' ); function change_num_posts_in_grid( $query ) { global $wp_the_query; if( $query->is_main_query() && is_home() && is_paged() ) { $query->set( 'posts_per_page', '5' ); } }
Learn more about Using The Genesis Grid Loop For Different Home Post Layouts.
Change Content Limit For Specific Category
You can also overwrite the WordPress Reading Settings and customize the excerpt limit on any archive including your home, author, blog, category, search, and tag page archives.
add_filter('excerpt_length', 'specific_category_excerpt_length'); function specific_category_excerpt_length($length) { if(is_category('29') ) { return 20; } }
The code above will change the excerpt length on the category page with an i.d of 29 to a 20 word limit.
You can also add back HTML formatting tags stripped from excerpts by WordPress.
On top of this, you can use this code below to control the content limit of excerpts on specific archives and then also set others to display a set limit. Note: Your Genesis > Theme Settings > Content Archives must be set to display Excerpts and not Content Limit.
add_filter('excerpt_length', 'specific_category_excerpt_length'); function specific_category_excerpt_length($length) { if(in_category('web-design') ) { return 20; } else { return 500; } }
The above code displays a content limit for excerpts in the web design category of 20 and all other archives display a limit of 500.
Here’s some PHP code which includes an array of multiple categories:
add_filter('excerpt_length', 'specific_category_excerpt_length'); function specific_category_excerpt_length($length) { if(in_category(array( 153,154,156 ) ) ) { return 100; } else { return 300; } }
This code uses the category i.d’s and displays a content limit of 100 for 3 categories. All other archives display a limit of 300.
Learn more about customizing excerpts.
Custom Post Type (CPT)
Here’s the code which determines how many posts in a custom post type are displayed on the CPT’s archive page:
add_action( 'pre_get_posts', 'cpt_archive_items_limit' ); function cpt_archive_items_limit( $query ) { if( $query->is_main_query() && !is_admin() && is_post_type_archive( 'your-cpt' ) ) { $query->set( 'posts_per_page', '3' ); } }
Simply replace your-cpt in the code above with the name of your custom post type.
Conclusion
You can see for yourself that using WordPress hooks and filters also work perfectly in Genesis.
Similar Solutions
- Setting To Display Entry Excerpts on Any Archive Page Template
- Code to Set Genesis Content Archive Limit
- Display Full Post Content or Excerpts On Specific Archive Pages
- Customize Archive Pages Conditionally Using Pre Get Posts
- Display Excerpts On Blog Page & Full Content On Other Archives in Genesis
Was This Tutorial Helpful?