Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am pretty new to Wordpress, especially when PHP programming is concerned. I am using Ciola Theme from Theme Forest. What I would like to achieve is to display a sub menu under the main menu, but only for a specific category. I added menu in theme's core-functions.php:

add_theme_support( 'menus' );
    // registering menus
    register_nav_menus(
        array(
    'top' => 'Top Navigation Menu', // top nav
    'main' => 'Main Navigation Menu', // main nav in header
    'wybrzeze' => 'Wybrzeże Navigation Menu', // wybrzeze nav in header
    'footer' => 'Footer Navigation Menu',  // secondary nav in footer
        )
    );

My entry is wybrzeze, Wybrzeże Navigation menu.

I then edited the header.php file to try to add some information my theme supporter asked me to fill:

<!-- Holding main menu -->
        <?php  if ( has_nav_menu( 'main' ) ) { 
                    $cb_main_menu = wp_nav_menu(
                        array(
                            'echo'           => FALSE, 
                            'container_class' => 'cb-main-menu',
                            'theme_location' => 'main',                    
                            'depth' => 0,                                   
                            'walker' => new CB_Walker,                                  
                            'items_wrap' => '<ul class="nav main-nav clearfix sf-menu">%3$s</ul>',
                            )); 
                }
        ?>

<!-- Holding Wybrzeze menu -->
        <?php  if ( has_nav_menu( 'wybrzeze' ) ) { 
                    $cb_main_menu = wp_nav_menu(
                        array(
                            'echo'           => FALSE, 
                            'container_class' => 'cb-main-menu',
                            'theme_location' => 'main',                    
                            'depth' => 0,                                   
                            'walker' => new CB_Walker,                                  
                            'items_wrap' => '<ul class="nav main-nav clearfix sf-menu">%3$s</ul>',
                            )); 
                }
        ?>

If I understand it correctly, this is the place I have to add my sub-menu. At the very end of header.php there are divs which are responsible for displaying the "main" menu:

<nav role="navigation">

         <div id="cb-main-menu" class="wrap clearfix"><?php if ( has_nav_menu( 'main' ) ) { echo $cb_main_menu; } ?> </div>
                     <div id="cb-main-menu-mob" class="wrap clearfix"><div id="cb-mob-dropdown-main"></div><?php if ( has_nav_menu( 'main' ) ) {  main_nav(); } ?></div>

Now, my question is: is it possible to achieve something like on this picture?

Is there any way to make the second line of menu display only for a chosen category?

I was thinking about using if/else PHP loop and WP reference <?php is_category( $category ); ?> but unfortunately I have no idea how to do this and I do not want to break the theme... I will really appreciate your help :)

UPDATE & SOLUTION:

Thanks to Bindiya Patoliya I have found the solution:

<?php if(is_category('teatr-wybrzeze')) {
wp_nav_menu( array(
'container_id' => 'cb-main-menu',
'container_class' => 'wrap clearfix',
'theme_location' => 'rafalmenu',                    
'depth' => 0,                                                                   
'items_wrap' => '<ul class="nav main-nav clearfix sf-menu">%3$s</ul>',
'walker' => new CB_Walker
) );
} ?>

It works great now! Thank you very much!

share|improve this question
add comment

3 Answers

up vote 0 down vote accepted

Yes,You can do it by

if(is_category()) {
wp_nav_menu( array(
'theme_location' => 'menu-97226',
'walker' => new Menu_Walker_97226()
) );
}

while calling menu in header file.

share|improve this answer
    
Thanks:) I added this to header.php but there was a fatal error concerning walker_97226. I changed it a bit and now the second menu appears under the main one :) Unfortunately, it displays the same content and I do not know why... here is the snippet: <?php if(is_category('teatr-wybrzeze')) { wp_nav_menu( array( 'container_id' => 'cb-main-menu', 'container_class' => 'wrap clearfix', 'theme_location' => 'main', 'depth' => 0, 'items_wrap' => '<ul class="nav main-nav clearfix sf-menu">%3$s</ul>', 'walker' => new CB_Walker() ) ); } ?> –  Rafał Wyszomirski Jul 6 '13 at 13:00
add comment

Hello Rafał Wyszomirski,

No need to create second menu.You can create submenu pages(as a category) in main menu and then customize the look of submenu as you wish like horizontal/vertical.

Hope this will help you.

share|improve this answer
    
Unfortunately I cannot render your idea in my head. The most important thing I want to achieve is that I do not wish to have make another dropdown menu. I would just want this sub-menu be visible only on the category page. –  Rafał Wyszomirski Jul 5 '13 at 7:59
add comment

UPDATE & SOLUTION:

Thanks to Bindiya Patoliya I have found the solution:

 <?php if(is_category('teatr-wybrzeze')) {
wp_nav_menu( array(
'container_id' => 'cb-main-menu',
'container_class' => 'wrap clearfix',
'theme_location' => 'rafalmenu',                    
'depth' => 0,                                                                   
'items_wrap' => '<ul class="nav main-nav clearfix sf-menu">%3$s</ul>',
'walker' => new CB_Walker
) );
} ?>

I am using the same CSS classes as for the main menu so it looks identical, it is displayed only in the selected category and has different content. It works great now! Thank you very much, Bindiya!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.