Return to Support

different sec. menu's per page

Home Forums Graphene WordPress theme Support different sec. menu's per page

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #2914
    Manasse
    Member

    Here’s another one… Yes WP keeps me quite busy, but hey, isn;t that part of the fun??

    I’m trying to set up three different secondary custom menu’s. The header menu will remain the same throughout the page, but when you go to band or fans, I’d like to have a secondary (custom) menu displaying all sub-pages in the band or fan part (there’s third one called media)

    So looking around the forum I found this https://forum.graphene-theme.com/graphene-support/conditional-secondary-menu#post-7017

    I tried out the code displayed there and filled it all in, pasted in my hild-theme’s function page and this is the code I ended up with (yes, I’m learning)

    <?php
    /* Register multiple secondary menus */
    register_nav_menus( array(
    'secondary-menu-band' => __( 'Secondary Menu (band)', 'graphene' ),
    'secondary-menu-media' => __( 'Secondary Menu (media)', 'graphene' ),
    'secondary-menu-fans' => __( 'Secondary Menu (fans)', 'graphene' ),
    ) );

    /* Conditionally display secondary menu */
    function graphene_multiple_secondary_menu( $args ){

    if ( is_page('band') )
    $args = array_merge( $args, array( 'theme_location' => 'secondary-menu-band' ) );
    if ( is_page('jaap') )
    $args = array_merge( $args, array( 'theme_location' => 'secondary-menu-band' ) );
    if ( is_page('muco') )
    $args = array_merge( $args, array( 'theme_location' => 'secondary-menu-band' ) );
    if ( is_page('dimitry') )
    $args = array_merge( $args, array( 'theme_location' => 'secondary-menu-band' ) );
    if ( is_page('media') )
    $args = array_merge( $args, array( 'theme_location' => 'secondary-menu-media' ) );
    if ( is_page('music') )
    $args = array_merge( $args, array( 'theme_location' => 'secondary-menu-media' ) );
    if ( is_page('pictures1') )
    $args = array_merge( $args, array( 'theme_location' => 'secondary-menu-media' ) );
    if ( is_page('video') )
    $args = array_merge( $args, array( 'theme_location' => 'secondary-menu-media' ) );
    if ( is_page('press1') )
    $args = array_merge( $args, array( 'theme_location' => 'secondary-menu-media' ) );
    if ( is_page('fans') )
    $args = array_merge( $args, array( 'theme_location' => 'secondary-menu-fans' ) );
    if ( is_page('forum-2') )
    $args = array_merge( $args, array( 'theme_location' => 'secondary-menu-fans' ) );
    if ( is_page('remixes') )
    $args = array_merge( $args, array( 'theme_location' => 'secondary-menu-fans' ) );
    if ( is_page('pictures') )
    $args = array_merge( $args, array( 'theme_location' => 'secondary-menu-fans' ) );
    if ( is_page('videos2') )
    $args = array_merge( $args, array( 'theme_location' => 'secondary-menu-fans' ) );
    if ( is_page('reviews') )
    $args = array_merge( $args, array( 'theme_location' => 'secondary-menu-fans' ) );
    return $args;
    }
    add_filter( 'graphene_secondary_menu_args', 'graphene_multiple_secondary_menu' );
    ?>

    in addition to that i’ve also made the secondary menu’s in the appearance->menu part

    It didn’t do anything… check http://www.twowaysociety.nl/hidden/

    So what am I doing wrong here?

    I also like to add the links to the three category archives I made in here, but can’t find the slugs

    #22631
    Prasanna SP
    Member

    Try using page IDs instead of page slug. Something like this,

    is_page(246) instead of is_page('fans')

    or

    is_page(array(246,'fans','Fans'));

    #22632
    Manasse
    Member

    Changed all the slugs into ID’s, but it’s still not working. Hmm. I think I’m doing something wrong in the custom menu => theme locations

    I haven’t chosen a secondary menu there, just created the three named above. But if I choose one of them, the theme’s showing that one everywhere and I wanted to have different 2nd menu’s for different pages…

    Well, thanks for the help, at least now I know it’s not wrong in the function.php. Maybe (just thinking out loud, you must know I’m a noob) I should call the function to take place at the secondary menu hook… (plz don’t laugh too loud if I’m wrong). What do you think (and more important) how should I do that??

    #22633
    Manasse
    Member

    Diving into the WordPress codex, getting my feet wet and all, I came across “lists”. What if I create this in my function.php

    <div id='second_navmenu_band>
    <ul>
    <?php wp_list_pages('include=9,231,237,235'); ?>

    and I’ll do the same for the fans and the media

    Then I’ll do this in style.css:

    #second_navmenu_band ul {margin: 0; padding: 0;
    list-style-type: none; list-style-image: none; }

    and will do the same for fans and media

    Now all I have to do is creating a header.php in my child theme and let the second_navmenu_band show up while someone is watching pages 9, 231, 237 & 235 and do the same for “second_navmenu_fans” and “second_navmenu_media” and their corresponding pages ***sighs***

    Do I think in the right way? Does anyone know how to get the right second_navmenu at the right moment? E.g. while watching page 9 second_navmenu_band shows up.

    (second_navmenu will be a secondary nevmenu under the headermenu….)

    #22634

    The functions file is only for functions, so including a <div> and a <ul> (and unclosed ones at that) will either do nothing or will only mess things up.

    #22635
    Manasse
    Member

    Ok, so I was getting off track there… Thought it was a good alternative to the code above. Just noticed there was a good tutorial somewhere about the hooks. Maybe I’d see that first and see if that’ll help me out in some way or another. Any suggestion is welcome, even if it’s just to point me in the right direction.

    keep you all updated…

    #22636
    Manasse
    Member

    Ok guys, after watching Josh’s action hook tutorials (both of ’em) I came up with the following. Don’t know if it will work, if any of you think I’m way off, please let me know 🙂

    I’ll put this in the child theme’s functions.php:

    function secondary_menu_listing(){

    ?>

    <div id=secondary_menu_listed><? php
    if (is_page (array(9,231,237,235));
    wp_list_pages (include=9,231,237,235);

    if (is_page (array(14,121,124,119,104));
    wp_list_pages (include=14,121,124,119,104);

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

    Then in style.css I can make the <div> look nice using this

    #secondary_menu_listed{
    list-style-type: none; list-style-image: none;
    {

    And some padding and other style’s (maybe just copying the original secondary_menu css)

    Am I right this time???

    #22637
    Manasse
    Member

    That’s not it, either. Got this error :

    “Parse error: syntax error, unexpected T_FUNCTION in /home/twowaysociety.nl/public_html/hidden/wp-content/themes/graphene-child/functions.php on line 3”

    I see now I forgot ” ) ” this one… and I used to be pretty good in math… Close all brackets…

    I’ll give it another go

    #22638
    Manasse
    Member

    OK… that was not working either *sighs*, but since I don’t give up that easily, I gave it another go with this:

    <?php
    if ( function_exists( 'register_nav_menus' ) ) {
    register_nav_menus(
    array(
    'secondary_menu_1' => 'Band Pages',
    'secondary_menu_2' => 'Media Pages'
    'secondary_menu_3' => 'Fans Pages'
    )
    );
    }

    ?>

    <? php

    if ( function_excists( 'secondary_menu_1')){
    ?><div id=secondary_menu_1>
    <? php wp_list_pages (include=' 9,231,237,235'); ?></div>

    <? php } ?>

    <? php

    if ( function_excists( 'secondary_menu_2')){
    ?><div id=secondary_menu_2>
    <? php wp_list_pages (include='14,121,124,119,104'); ?></div>

    <? php } ?>

    <? php

    if ( function_excists( 'secondary_menu_3')){
    ?><div id=secondary_menu_3>
    <? php wp_list_pages (include='246,230,252,254,259,257'); ?></div>

    <? php } ?>

    <? php

    if (is_page(array('9,231,237,235')));
    function ('secondery_menu_1')

    if (is_page(array('14,121,124,119,104')));
    function ('secondary_menu_2')

    if (is_page(array('246,230,252,254,259,257')));
    function ('secondary_menu_3')
    ?>

    <? php add_action ('graphene_before_content'); ?>

    resulted in the following error: `Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ‘)’ in /URL/graphene-child/functions.php on line 7

    It feels like I’m getting closer, but not sure if that’s really the case…

    #22639
    Josh
    Member

    I haven’t tested your code, so I don’t know if it’s correct or not.

    However, you don’t want to end php and then begin it again. For example, take out all the ?> <?php areas in the code.

    And this is a problem:

    php add_action ('graphene_before_content');

    Check out the codex on how to properly use action and filter hooks:

    http://codex.wordpress.org/Plugin_API

    #22640
    Manasse
    Member

    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
    }
    }
    ?>

    #22641
    Manasse
    Member

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

    #22642
    Josh
    Member

    I’m giving myself an egoboost now 🙂

    Feels so good, doesn’t it?? 🙂

    #22643
    Manasse
    Member

    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

    #22644

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

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

You must be logged in to reply to this topic.