different sec. menu's per page

  • Anonymous

    #22640

    YES! I’ve done it!!! someone suggested to use notepad++. I’ve to recommend it to everybody.. If you’d want to know how to do this, here’s how I solved it:

    Made a functions.php in my child-theme. I chose the action hook using Firebug (thanks Josh 4 tutorial). Then I did some research in the WP codex and this forum. Got a lot of errors. Tried to solve them one by one and ended up with the code I’m using now (I’d still have to dress it up in style.css; will give me some next problems). Used Graphene action hook widget area and a php-widget to call my home-brew-function.

    Hope this will give all newbies (like myself) a reason to keep on trying and yes, I’m giving myself an egoboost now 🙂 Maybe I’ll be a pro someday (unlikely, tho’)

    Anyway here’s the code:

    <?php

    function secondary_menu_listing(){

    ?>

    <div id="secondary_menu_band">

    <?php
    if (is_page (array(9, 231, 237, 235)))
    {
    wp_list_pages ('include=9,231,237,235') ?></div><?php
    }
    ?><div id="secondary_menu_media"><?php

    if (is_page (array(14, 121, 124, 119, 104)))
    {
    wp_list_pages ('include=14, 121, 124, 119, 104') ?></div><?php
    }
    ?><div id="secondary_menu_fans"><?php

    if (is_page (array(246, 230, 252, 254, 259, 257)))
    {
    wp_list_pages ('include=246, 230, 252, 254, 259, 257') ?></div><?php
    }
    }
    ?>

    Anonymous

    #22641

    PS for the result, check http://www.twowaysociety.nl/hidden/ (have to wait a few days for I’m not done styling it now…)

    Anonymous

    #22642

    I’m giving myself an egoboost now 🙂

    Feels so good, doesn’t it?? 🙂

    Anonymous

    #22643

    Hahaha, YES!!! Still not there, though… placed the lists in div’s but apparently I forgot the

    <li></li>
    or
    <ul></ul>

    .. Diving in the codex as we speak, trying to figure out what’s the difference and how to make it as nice as the original graphene’s secondary_menu

    Might have to take a look in the graphene files as well. But am confident now that I’ll figure it out. Not bad for a newbie, huh?

    Cheers

    Mod

    Kenneth John Odle

    #22644

    That, my friends, is how you get it done. Congratulations.

    Anonymous

    #22645

    Hahaha, last one on this; since I made ‘lists’, the menu had to be styled massively, to make it look like the original secondary menu’s. So I took a little look into what I was doing wrong in the first place; the first code I placed in this thread.

    Guess what.. It was perfect! The “multiple secondary menu” is shown in the “Appearance->Menu” window. I have six “places” I can put menus in. Besides the three original (Header, Secondary and Footer), with the first code, I created page-conditioned nav’s, having the same styling as the original has… Beautiful! For having the page conditions (and to shorten my function list) I changed the long

    if ( is_page('band') )
    $args = array_merge( $args, array( 'theme_location' => 'secondary-menu-band' ) );
    >>>>>>
    if ( is_page('muco') )
    $args = array_merge( $args, array( 'theme_location' => 'secondary-menu-band' ) );

    into

    if ( is_page(1,2,3,4,5,6) )
    $args = array_merge( $args, array( 'theme_location' => 'secondary-menu-one' ) );
    if ( is_page(7,8,9,10) )
    $args = array_merge( $args, array( 'theme_location' => 'secondary-menu-two' ) );
    if ( is_page(11,14,17,18) )
    $args = array_merge( $args, array( 'theme_location' => 'secondary-menu-three' ) );

    Done. If anyone need the code just make sure you don’t put single-quotes ( ‘ ) where you use ID’s (I did, giving lot’s of errors).

    The End

    olenz

    #22646

    Nice what you have done, and I will steal it for our site!

    Do I assume correct that you hooked into the “graphene_top_menu” hook? If so, how did you get rid of the menu shadow below it?

    And, just as an idea: wouldn’t it be possible to use the page hierarchy to specify for which pages which secondary menu is shown? Then you wouldn’t have to specify a hard-coded list in the code.

    And another issue: If I see it right, when you choose a page in the secondary menu, then the corresponding top-level menu is not selected anymore. Any way around that?

    Anonymous

    #22647

    I hope you tried the FIRST code on this thread, ’cause I messed it up after that one, trying to figure it out myself. Anyway, thanks for the credits, but the coding is all MR Graphene himself (Khairul Syahir.

    DON’T put it in your hard code but set up a child theme. You can put this code in your child theme’s function.php. That way the changes you made will stay when Graphene is updating…

    So I’m not sure if ‘hard-coding’ will be that much of an issue; Maybe MR Graphene can think about making it an option when updating the theme..

    About your other issue. Well, the secondary navbars are working just fine for me, though your suggestion is one I should think about, meaning you’ve got a point there. I think this should be done in your child theme’s style.css. Unfortunately for you (and especially for yours truly) I really don’t know anything about css 🙂

    With my littlest of knowledge I think you should try to tweak some hovering… Try Firubug (Firefox plugin) to see what you can adjust in style.css. There a GREAT tutorial by a moderater on here (search for style.css tutorial).

    Ok then; love to have that hover, so keep us informed!

    Hmm. That’s an interesting question.

    olenz

    #22648

    I have hacked a bit today and chosen a very different approch to yours, and I believe I have found a much more elegant solution.

    You can see it in action on http://espressomd.org/wordpress/ (some minutes after posting this)

    My child theme only requires some code in “functions.php” (see below).

    When this is used, the secondary menu will simply show the second level of your main menu.

    This solves some of the problems with your approach:

    • The shadow below the top-level menu
    • The hard-coded list of pages (just use the main menu)

    I think I will ask the author whether he wants to include the code into the theme as a possible option.

    Here comes the code:

    /* removing this filter removes the ancestor class stuff */
    add_action( 'after_setup_theme', 'graphene_child_theme_setup' );
    function graphene_child_theme_setup() {
    remove_filter( 'nav_menu_css_class', 'graphene_add_ancestor_class', 2, 10);
    }

    /* this filter sets the depth of the header menu to 1 */
    add_filter('graphene_header_menu_args', 'graphene_child_set_depth_to_one' );
    function graphene_child_set_depth_to_one($args) {
    $args['depth'] = 1;
    return $args;
    }

    /* this filter adds the SubMenu_Walker and sets the depth to 1 */
    add_filter('graphene_secondary_menu_args', 'graphene_child_set_submenu_walker' );
    function graphene_child_set_submenu_walker($args) {
    $args['depth'] = 2;
    $args['theme_location'] = 'Header Menu';
    $args['walker'] = new SubMenu_Walker();
    return $args;
    }

    class SubMenu_Walker extends Walker_Nav_Menu {
    function __construct($min_depth = 1) {
    $this->min_depth = $min_depth;
    $this->in_current_submenu = false;
    }

    function start_el( &$output, $item, $depth, $args ) {
    if ($depth == $this->min_depth-1)
    $this->in_current_submenu = $item->current_item_parent || $item->current;
    else if ($depth >= $this->min_depth && $this->in_current_submenu)
    parent::start_el( $output, $item, $depth - $this->min_depth, $args );
    }
    function end_el( &$output, $item, $depth, $args ) {
    if ($depth >= $this->min_depth && $this->in_current_submenu)
    parent::end_el( $output, $item, $depth - $this->min_depth, $args );
    }

    function start_lvl( &$output, $depth, $args) {
    if ($depth >= $this->min_depth && $this->in_current_submenu)
    parent::start_lvl( $output, $depth - $this->min_depth, $args);
    }
    function end_lvl( &$output, $depth, $args) {
    if ($depth >= $this->min_depth && $this->in_current_submenu) {
    $this->in_current_element = false;
    parent::end_lvl( $output, $depth - $this->min_depth, $args);
    }
    }

    }
Viewing 9 posts - 11 through 19 (of 19 total)
  • You must be logged in to reply to this topic.
Do NOT follow this link or you will be banned from the site!