Skip to content

Instantly share code, notes, and snippets.

@ChrisCree
Created July 26, 2013 02:32
Show Gist options
  • Save ChrisCree/6085625 to your computer and use it in GitHub Desktop.
Save ChrisCree/6085625 to your computer and use it in GitHub Desktop.
Code for home.php to display only 1 post category on the home page blog.
<?php
do_action( 'genesis_home' );
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'wsm_custom_loop' );
function wsm_custom_loop() {
global $paged;
$args = ( array(
'category_in' => 3, // ID of category to be displayed
'ignore_sticky_posts' => 1,
'paged' => $paged,
'posts_per_page' => 10,
) );
genesis_custom_loop( $args );
}
genesis();
@ChrisCree
Copy link
Author

Here's a better option. Just drop this into your functions.php file instead:

// Exclude categories from posts
add_action( 'pre_get_posts', 'wsm_exclude_categories_from_main_blog' );
function wsm_exclude_categories_from_main_blog( $query ) {

    if( $query->is_main_query() && $query->is_home() ) {
        $query->set( 'cat', '-27,-156' ); 
        // where 27 & 156 are the category ID numbers to be excluded
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment