Exclude category from home.php Genesis 2.0 – help?

Community Forums Forums Design Tips and Tricks Exclude category from home.php Genesis 2.0 – help?

This topic is: not resolved

This topic contains 14 replies, has 9 voices, and was last updated by  braddalton 1 month, 2 weeks ago.

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #55797

    merlene
    Participant
    Post count: 7

    I’ve just installed Genesis 2.0 and Eleven40 Pro on a new site. I’ve worked with themes & previous versions of Genesis and while I can sometimes reason things out (and I’m a master at copy & paste) I cannot fathom out how to remove a specific category from the home.php grid loop. I know I’ve managed to hack/slash/copy/paste something to exclude a category in the past (on a past site which is no longer available) but I’m not getting anywhere with it this time.

    #55954

    AC
    Blocked
    Post count: 7712

    You know… sometimes I just don’t fart around with these things. I use a plugin called Simply Exclude and it does the trick for me for excluding things all over the place.

    http://wordpress.org/plugins/simply-exclude/

    #56045

    merlene
    Participant
    Post count: 7

    Thanks @anitac – I’ll keep the plugin in mind but I’d prefer to find a way to do this using the functions/grid loop rather than a plugin if at all possible.

    #61336

    jronaldlee
    Participant
    Post count: 14

    I know you said you’d rather do it in the loop, but here’s another plugin option (I found Simply Exclude did NOT work for me).

    http://wordpress.org/plugins/ultimate-category-excluder/

    #80915

    Brian Dusablon
    Participant
    Post count: 23

    merlene, did you ever find a solution? I had it working on a site a while back, I think with some code from Brad Dalton. But now it’s not working.


    #80917

    genwrock
    Member
    Post count: 586

    try this code in your functions.php file

    add_filter('genesis_grid_loop_args', 'exclude_category_from_home');
    function exclude_category_from_home($args){
       $args['cat'] = '-2'; //Please add your category id
      return $args;
    }

    My Genesis Child Themes Work | Please Follow Me on Twitter If I’ve helped.

    • This reply was modified 9 months ago by  genwrock.
    • This reply was modified 9 months ago by  genwrock.
    #80920

    Brian Dusablon
    Participant
    Post count: 23

    That didn’t work for me. Here’s my entire functions.php file.

    <?php
    //* Start the engine
    include_once( get_template_directory() . '/lib/init.php' );
    
    //* Set Localization (do not remove)
    load_child_theme_textdomain( 'eleven40', apply_filters( 'child_theme_textdomain', get_stylesheet_directory() . '/languages', 'eleven40' ) );
    
    //* Child theme (do not remove)
    define( 'CHILD_THEME_NAME', __( 'eleven40 Pro Theme', 'eleven40' ) );
    define( 'CHILD_THEME_URL', 'http://my.studiopress.com/themes/eleven40/' );
    define( 'CHILD_THEME_VERSION', '2.0' );
    
    //* Add HTML5 markup structure
    add_theme_support( 'html5' );
    
    //* Add viewport meta tag for mobile browsers
    add_theme_support( 'genesis-responsive-viewport' );
    
    //* Load Lora and Oswald Google fonts
    add_action( 'wp_enqueue_scripts', 'eleven40_google_fonts' );
    function eleven40_google_fonts() {
    	wp_enqueue_style( 'google-font', '//fonts.googleapis.com/css?family=Lora:400,700|Oswald:400', array(), PARENT_THEME_VERSION );
    }
    
    //* Add new featured image size
    add_image_size( 'grid-featured', 270, 100, TRUE );
    
    //* Add support for custom header
    add_theme_support( 'custom-header', array(
    	'width'			=> 320,
    	'height'		=> 65,
    	'header-selector'	=> '.site-header .title-area',
    	'header-text'		=> false
    ) );
    
    //* Add support for structural wraps
    add_theme_support( 'genesis-structural-wraps', array(
    	'header',
    	'nav',
    	'subnav',
    	'site-inner',
    	'footer-widgets',
    	'footer'
    ) );
    
    //* Add support for additional color styles
    add_theme_support( 'genesis-style-selector', array(
    	'eleven40-pro-blue'	=> __( 'eleven40 Pro Blue', 'eleven40' ),
    	'eleven40-pro-green'	=> __( 'eleven40 Pro Green', 'eleven40' ),
    	'eleven40-pro-red'	=> __( 'eleven40 Pro Red', 'eleven40' )
    ) );
    
    //* Reposition the site description
    remove_action( 'genesis_site_description', 'genesis_seo_site_description' );
    //* add_action( 'genesis_before_content_sidebar_wrap', 'genesis_seo_site_description' );
    
    //* Reposition the primary navigation menu
    remove_action( 'genesis_after_header', 'genesis_do_nav' );
    add_action( 'genesis_before_content_sidebar_wrap', 'genesis_do_nav' );
    
    //* Reposition the secondary navigation menu
    remove_action( 'genesis_after_header', 'genesis_do_subnav' );
    add_action( 'genesis_before_content_sidebar_wrap', 'genesis_do_subnav' );
    
    //* Add support for 3-column footer widgets
    add_theme_support( 'genesis-footer-widgets', 3 );
    
    // Home Category Removal
    add_filter('genesis_grid_loop_args', 'exclude_category_from_home');
    function exclude_category_from_home($args){
       $args['cat'] = '-7'; //Please add your category id
      return $args;
    }
    
    // AG ADDED
    
    // Register Genesis Menus
    add_theme_support ( 'genesis-menus' , array ( 'primary' => 'Primary Navigation Menu' , 'secondary' => 'Secondary Navigation Menu' ,'mobile' => 'Mobile Navigation Menu' ) );
    
    // Add Support for Structural Wraps
    add_theme_support( 'genesis-structural-wraps', array( 'header', 'nav', 'menu-mobile', 'subnav', 'site-inner', 'footer-widgets', 'footer') );
    
    add_action( 'genesis_before_header', 'gst_do_mobilenav' );
    /**
     * Create the Mobile Navigation Menu.
     *
     * @author Brad Potter
     * 
     * @link http://www.bradpotter.com
     *
     * Based on code from the StudioPress Genesis Framework 2.0
     */
    function gst_do_mobilenav() {
    
    	//* Do nothing if menu not supported
    	if ( ! genesis_nav_menu_supported( 'mobile' ) )
    		return;
    
    	//* If menu is assigned to theme location, output
    	if ( has_nav_menu( 'mobile' ) ) {
    
    		$class = 'menu genesis-nav-menu menu-mobile';
    		if ( genesis_superfish_enabled() )
    			$class .= ' js-superfish';
    
    		$args = array(
    			'theme_location' => 'mobile',
    			'container'      => '',
    			'menu_class'     => $class,
    			'echo'           => 0,
    		);
    
    		$mobilenav = wp_nav_menu( $args );
    
    		//* Do nothing if there is nothing to show
    		if ( ! $mobilenav )
    			return;
    
    		$mobilenav_markup_open = genesis_markup( array(
    			'html5'   => '<nav %s>',
    			'xhtml'   => '<div id="mobilenav">',
    			'context' => 'nav-mobile',
    			'echo'    => false,
    		) );
    		
    		$mobilenav_markup_open .= genesis_structural_wrap( 'menu-mobile', 'open', 0 );
    
    		$mobilenav_markup_close  = genesis_structural_wrap( 'menu-mobile', 'close', 0 );
    		$mobilenav_markup_close .= genesis_html5() ? '</nav>' : '</div>';
    
    		$mobilenav_output = $mobilenav_markup_open . $mobilenav . $mobilenav_markup_close;
    
    		echo apply_filters( 'gst_do_mobilenav', $mobilenav_output, $mobilenav, $args );
    
    	}
    
    }
    
    add_filter( 'genesis_attr_nav-mobile', 'gst_attributes_nav_mobile' );
    /**
     * Add Attributes for Mobile Navigation Menu.
     * 
     * @author Brad Potter
     * 
     * @link http://www.bradpotter.com
     *
     * Based on code from the StudioPress Genesis Framework 2.0
     */
    function gst_attributes_nav_mobile( $attributes ) {
    
    	$attributes['role']      = 'navigation';
    	$attributes['itemscope'] = 'itemscope';
    	$attributes['itemtype']  = 'http://schema.org/SiteNavigationElement';
    
    	return $attributes;
    }
    
    /**
     * Register and Enqueue Mobile Navigation Menu script
     * 
     * @author Brad Potter
     * 
     * @link http://www.bradpotter.com
     */
    function gst_mobilemenu_script() {
      	
    	wp_register_script( 'mobile-menu', get_stylesheet_directory_uri() . '/js/mobilemenu.js', array('jquery'), '1.0.0', false );
    	wp_enqueue_script( 'mobile-menu' );
    
     }
    add_action('wp_enqueue_scripts', 'gst_mobilemenu_script');
    
    /**Register Widgets*/
    
    genesis_register_sidebar( array(
        'id' => 'home-featured',
        'name' => __( 'Home Featured', 'eleven40' ),
        'description' => __( 'This is the home featured section.', 'eleven40' ),
    ) );

    #80924

    genwrock
    Member
    Post count: 586

    what is your site URL? Home page is using the grid loop?


    My Genesis Child Themes Work | Please Follow Me on Twitter If I’ve helped.

    #80928

    Brian Dusablon
    Participant
    Post count: 23

    mydivorcepal.com


    #81012

    genwrock
    Member
    Post count: 586

    Ah! Please remove my code. It will not work that way.


    My Genesis Child Themes Work | Please Follow Me on Twitter If I’ve helped.

    #81028

    braddalton
    Participant
    Post count: 9769

    This is what i use.

    Please copy ALL the code from the view raw link and paste it at the end of your child themes functions.php file using a text editor like Notepad++

    Change the category i.d to your own.

    This code includes the is_home() conditional tag which returns true on your posts page according to your Reading Settings.


    Specializing In StudioPress Child Theme Customization.
    500+ StudioPress Tutorials

    #81100

    kimboosan
    Member
    Post count: 1

    Thank you, Brad, that code worked perfectly!

    ::::kbs


    ::::kbs
    kimboosan.net

    #111681

    dev
    Participant
    Post count: 457

    Brad (or anyone): This is close to what I want to do on the Eleven40 theme.

    The default is for it to pick up EVERY category on home page. I want to exclude ALL but one of them. Another way to say this is that I only want to show just one of the categories.

    What magic code will do that for me?

    ============ UPDATE ===========
    ============ UPDATE ===========
    ============ UPDATE ===========

    I found it. The minus sign means “exclude” I took it off and that means “include”:

    $query->set( ‘cat’, ’3′ );

    (3 is the category ID of the posts I want to display.)

    Hope this helps someone.

    #117039

    krystyn
    Participant
    Post count: 148

    I’ve added this code here http://dudemom.com/ trying to exclude category 3119 from the homepage. I added the code to functions.php (currently) after trying home.php with neither removing it from home.

    Will this not work with the balance theme?

    #117066

    braddalton
    Participant
    Post count: 9769

    It only works on the home page which is determined by your Reading > Settings for the Posts Page.


    Specializing In StudioPress Child Theme Customization.
    500+ StudioPress Tutorials

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

You must be logged in to reply to this topic.