Want only one category to show up on Blog

Community Forums Forums General Discussion Want only one category to show up on Blog

This topic is: resolved

This topic contains 10 replies, has 2 voices, and was last updated by  benjeeno 1 year, 6 months ago.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #32135

    benjeeno
    Participant
    Post count: 266

    How do I get only one category to show up on the Blog?

    #32137

    Robin
    Participant
    Post count: 318

    Generally, I use the blog template for the page template, and add a custom field:

    Name is query_args
    Value is cat=xx (xx being the ID number of your desired category)

    HTH


    I do the best I can with what I’ve got. (say hey on twitter)

    #32139

    benjeeno
    Participant
    Post count: 266

    I’m wanting to do this with the Agency’s home page, altering the home.php file. I’ve already gotten the blog to show under the slider. Will this method you are suggesting with the arg code work the way I have it? I have no idea how the code string should actually look.

    #32162

    Robin
    Participant
    Post count: 318

    The query_args works as a custom field in a blog page template. If you’ve already modified the home.php then it’s hard to know what you need to do to show only one category without seeing that code. You can post it here (and a link to your site would probably help, too, but to see what is going on with the php, we need to see it).


    I do the best I can with what I’ve got. (say hey on twitter)

    #32164

    benjeeno
    Participant
    Post count: 266

    I appreciate your help.

    http://www.siegfriedmedia.com/rivasrocks is the site. I have some stand-in posts, they are two categories. I want only one of the categories to show.

    Here’s the home.php code:

    [php]

    add_action( ‘genesis_meta’, ‘agency_home_genesis_meta’ );
    /**
    * Add widget support for homepage. If no widgets active, display the default loop.
    *
    */
    function agency_home_genesis_meta() {

    if ( is_active_sidebar( ‘home-welcome’ ) || is_active_sidebar( ‘home-slider’ ) || is_active_sidebar( ‘home-left’ ) || is_active_sidebar( ‘home-middle’ ) || is_active_sidebar( ‘home-right’ ) ) {

    //remove_action( ‘genesis_loop’, ‘genesis_do_loop’ );
    add_action( ‘genesis_after_header’, ‘agency_home_welcome_helper’ );
    //add_action( ‘genesis_loop’, ‘agency_home_loop_helper’ );
    //add_filter( ‘genesis_pre_get_option_site_layout’, ‘__genesis_return_full_width_content’ );
    add_filter( ‘body_class’, ‘add_body_class’ );

    function add_body_class( $classes ) {
    $classes[] = ‘agency’;
    return $classes;
    }

    }
    }

    function agency_home_welcome_helper() {

    if ( is_active_sidebar( ‘home-slider’ ) ) {
    echo ‘<div id="home-slider">’;
    dynamic_sidebar( ‘home-slider’ );
    echo ‘</div><!– end #home-slider –>’;
    }

    if ( is_active_sidebar( ‘home-welcome’ ) ) {
    echo ‘<div id="home-welcome">’;
    dynamic_sidebar( ‘home-welcome’ );
    echo ‘</div><!– end #home-welcome –>’;
    }

    }

    function agency_home_loop_helper() {

    if ( is_active_sidebar( ‘home-left’ ) || is_active_sidebar( ‘home-middle’ ) || is_active_sidebar( ‘home-right’ ) ) {

    echo ‘<div id="home">’;

    echo ‘<div class="home-left">’;
    dynamic_sidebar( ‘home-left’ );
    echo ‘</div><!– end .home-left –>’;

    echo ‘<div class="home-middle">’;
    dynamic_sidebar( ‘home-middle’ );
    echo ‘</div><!– end .home-middle –>’;

    echo ‘<div class="home-right">’;
    dynamic_sidebar( ‘home-right’ );
    echo ‘</div><!– end .home-right –>’;

    echo ‘</div><!– end #home –>’;

    }

    }

    genesis();
    [/php]
     

    #32247

    Robin
    Participant
    Post count: 318

    Hmmmmm…this is not something I’ve done before. But try doing the first example from this post? You’ll want to uncomment your remove_action for the genesis loop because you’ll be replacing the genesis standard loop with your own custom one.


    I do the best I can with what I’ve got. (say hey on twitter)

    #32253

    benjeeno
    Participant
    Post count: 266

    Yah, but can I have the same arrangement with slider above the blog and have that be the homepage, I guess, not even using the home.php page at all, but having this template page be the homepage?

    #32313

    benjeeno
    Participant
    Post count: 266

    Robin,

    In the Genesis Theme Settings panel you can choose display/exclude by a single category and/or exclude by post ID but this only works on the Blog page. It worked but only for the Blog page. I need it for the home.php page where I have posts showing under the responsive slider.

    I’d use the Blog page as the homepage of my site if I could know how to make the main URL not bring up the home.php page and also be able to install the responsive slider above the blog posts on the Blog page.

    #32362

    benjeeno
    Participant
    Post count: 266

    Using the WP query code here in Bill’s tutorial (http://www.billerickson.net/customize-the-wordpress-query/), what code would I add into my home.php (code below) to exclude a category or post IDs? Bill Erickson’s code is shown to go into the functions.php file but that didn’t seem to work for what I’m trying, or maybe I did it wrong. I don’t understand enough about php to figure out what to do with the query code.

    [php]

    add_action( ‘genesis_meta’ , ‘agency_home_genesis_meta’ );
    /**
    * Add widget support for homepage. If no widgets active, display the default loop.
    *
    */
    function agency_home_genesis_meta() {

    if ( is_active_sidebar( ‘home-welcome’ ) || is_active_sidebar( ‘home-slider’ ) || is_active_sidebar( ‘home-left’ ) || is_active_sidebar( ‘home-middle’ ) || is_active_sidebar( ‘home-right’ ) ) {

    //remove_action( ‘genesis_loop’, ‘genesis_do_loop’ );
    add_action( ‘genesis_after_header’ , ‘agency_home_welcome_helper’ );
    //add_action( ‘genesis_loop’, ‘agency_home_loop_helper’ );
    //add_filter( ‘genesis_pre_get_option_site_layout’, ‘__genesis_return_full_width_content’ );
    add_filter( ‘body_class’ , ‘add_body_class’ );

    function add_body_class( $classes ) {
    $classes [] = ‘agency’ ;
    return $classes ;
    }

    }
    }

    function agency_home_welcome_helper() {

    if ( is_active_sidebar( ‘home-slider’ ) ) {
    echo ‘
    <div id="home-slider">’</div>
    ;
    dynamic_sidebar( ‘home-slider’ );
    echo ‘
    <!– end #home-slider –>’ ;
    }

    if ( is_active_sidebar( ‘home-welcome’ ) ) {
    echo ‘
    <div id="home-welcome">’</div>
    ;
    dynamic_sidebar( ‘home-welcome’ );
    echo ‘
    <!– end #home-welcome –>’ ;
    }

    }

    function agency_home_loop_helper() {

    if ( is_active_sidebar( ‘home-left’ ) || is_active_sidebar( ‘home-middle’ ) || is_active_sidebar( ‘home-right’ ) ) {

    echo ‘
    <div id="home">’</div>
    ;

    echo ‘
    <div class="home-left">’</div>
    ;
    dynamic_sidebar( ‘home-left’ );
    echo ‘
    <!– end .home-left –>’ ;

    echo ‘
    <div class="home-middle">’</div>
    ;
    dynamic_sidebar( ‘home-middle’ );
    echo ‘
    <!– end .home-middle –>’ ;

    echo ‘
    <div class="home-right">’</div>
    ;
    dynamic_sidebar( ‘home-right’ );
    echo ‘
    <!– end .home-right –>’ ;

    echo ‘
    <!– end #home –>’ ;

    }

    }

    genesis();

    [/php]

    #32366

    Robin
    Participant
    Post count: 318

    Well, Bill Erickson is a major guru, so things he says are worth paying attention to. His function seems pretty straightforward–did you check the category ID number to make sure that was correct? His goes in the functions.php file so you shouldn’t mess with the home.php to use it. I think.

    Otherwise, you could try modifying your home.php that you posted, starting with this line:
    /** Replace the standard loop with our custom loop */
    remove_action( 'genesis_loop', 'genesis_do_loop' );
    add_action( 'genesis_loop', 'child_do_custom_loop' );

    function child_do_custom_loop() {

    global $paged; // current paginated page
    global $query_args; // grab the current wp_query() args
    $args = array(
    'category__not_in' => 42, // exclude posts from this category
    'paged' => $paged, // respect pagination
    );

    genesis_custom_loop( wp_parse_args($query_args, $args) );

    }
    and change 42 to whatever your category number is.

    Another option, if you don’t necessarily want to use the home.php template, is to remove it from the situation altogether (just rename it to home.php.old for starters if you want to change your mind). You could use a static page running the blog template as your home page and do query_args in a custom field, but you would have to figure out how to handle the slider in that situation. I don’t think it’s the right solution for what you probably want to do.


    I do the best I can with what I’ve got. (say hey on twitter)

    #32367

    benjeeno
    Participant
    Post count: 266

    Thanks Robin, I see what points you are making. At first when I tried Bill’s code I was using the post IDs and not the cat IDs. I got it to work excluding the category I wanted using the cat ID, using the code below in the functions.php file.

    <code>

    add_action( ‘pre_get_posts’, ‘be_exclude_category_from_blog’ );

    /**
    * Exclude Category from Blog
    *
    * @author Bill Erickson
    * @link http://www.billerickson.net/customize-the-wordpress-query/
    * @param object $query data
    *
    */
    function be_exclude_category_from_blog( $query ) {

    if( $query->is_main_query() && $query->is_home() ) {
    $query->set( ‘cat’, ‘-4′ );
    }

    }
    </code>

    This http://www.wordpress.org/extend/plugins/display-posts-shortcode/ also works very well. I played around with it for a while, but wouldn’t work in my situation because I’m altering the home.php file.

Viewing 11 posts - 1 through 11 (of 11 total)

The topic ‘Want only one category to show up on Blog’ is closed to new replies.