WordPress.org

Ready to get started?Download WordPress

Forums

Genesis Simple Menus
[resolved] automatically apply to all posts within specific category? (7 posts)

  1. Gretchen Louise
    Member
    Posted 1 year ago #

    I'd love to see an option added to this plugin to apply the custom subnav menu to each post within a specific category, not just each category page. It's tedious to remember to change the menu option for each post--why not just give an option to apply to all posts within specific categories?

    Previously, using Prose, I'd accomplished that with this bit of code--but when I reverted to Genesis itself, it breaks the menu layout. Perhaps it would be a starting point?

    // Subnav dependent on category
    remove_action('genesis_after_header', 'genesis_do_subnav');
    add_action('genesis_after_header', 'custom_do_subnav');
    function custom_do_subnav() {
    echo '<div id="subnav"><div>';
    if ( in_category('tech')  && !is_front_page() && !is_home() ) { wp_nav_menu( array('menu' => 'Tech' ));
    }
    else {
    genesis_do_subnav();
    }
    echo '</div></div>';
    }

    http://wordpress.org/extend/plugins/genesis-simple-menus/

  2. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 1 year ago #

    A post can have multiple categories and/or tags. To make the feature you are asking for work it would need to have a system for you to assign a unique priority per category & tag (and terms in custom taxonomies if your install had custom taxonomies). It's not practical to implement.

  3. Gretchen Louise
    Member
    Posted 1 year ago #

    I see your point. The code in my functions.php worked well enough. I guess I just need to figure out why it's breaking the menu format.

    Thank you for your plugin.

  4. Ron Rennick
    MultiSite Guru
    Plugin Author

    Posted 1 year ago #

    You're welcome.

  5. kriskl
    Member
    Posted 10 months ago #

    @Gretchen Louise Hi, I am looking for the same functionality. did you manage to make it work??

    (I know Ron said, a post can have multiple categories..

    but in my case, I use always 1 category per post..

    so if the code above was reworked for genesis... it would be really helpful!

    kris

  6. Gretchen Louise
    Member
    Posted 10 months ago #

    I don't remember now who helped me fix it, but this is the code I'm using (and it works!). Hope it's helpful for you, Kriskl.

    // Sidebar dependent on category
    add_action('get_header', 'child_sidebar_logic');
    function child_sidebar_logic() {
    if ( function_exists('ss_do_sidebar') ) {
    remove_action('genesis_sidebar', 'ss_do_sidebar');
    } else {
    remove_action('genesis_sidebar', 'genesis_do_sidebar');
    }
    add_action('genesis_sidebar', 'child_do_sidebar');
    }
    function child_do_sidebar() {
    if ( in_category( 'tech' ) && !is_front_page() && !is_home() ) { if ( dynamic_sidebar( 'tech' ) ) return;
    }
    if ( function_exists('ss_do_sidebar') ) ss_do_sidebar();
    else genesis_do_sidebar();
    }
    // Subnav dependent on category
    remove_action('genesis_after_header', 'genesis_do_subnav');
    add_action('genesis_after_header', 'custom_do_subnav');
    function custom_do_subnav() {
    echo '<div id="subnav"><div class="wrap"><ul id="menu-tech-2" class="menu genesis-nav-menu menu-secondary superfish sf-js-enabled">';
    if ( is_single && in_category('tech')) { wp_nav_menu( array('menu' => 'Tech' ));
    }
    else {
    genesis_do_subnav();
    }
    echo '</ul></div></div>';
    }
  7. kriskl
    Member
    Posted 10 months ago #

    Oh, thank you for much Louise!
    it almost works perfectly. will have to to some tweaking (for some reason, it loads conditional menu on the front page..
    but anyway, thank you! it is what I was looking for

    Ron, there is a plugin to make single post for 1 category only called: Only One Category

    So maybe the idea to make the Genesis simple menus plugin - into Genesis Magic Menus not such a stupid idea :)

    provided that the "Only 1 Category" plugin is required for Genesis Magic Menus to work..

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic