0

this is the code i am using to call wp_nav_menu

<?php
     wp_nav_menu(
            array(
                'container_class' => 'menu-header',
                'theme_location' => '',
                'menu_id'         => 6,
                'depth' => 4
            )
        );
?>

the menu appears perfect on home page and single post pages, as seen here: http://www.enkitec.com/

but when i visit a category page e.g. http://www.enkitec.com/education/ the menu items change, it seems like some menu items don't appear.

note: i have only 1 menu in dashboard and it is set as default menu

strange thing is: the code above is included in header.php, so it is the same on all pages, but still the results are different on category page.

any help would be highly appreciated.

more over i am also including the code of my theme pages:

header.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="<?php bloginfo( 'charset' ); ?>" />
    <title><?php wp_title('-', true, 'right'); ?> <?php bloginfo('name'); ?></title>
    <meta name="description" content="<?php echo is_single() ? single_post_title('', true):bloginfo('name')." - ".bloginfo('description'); ?>" />
    <link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo('stylesheet_url'); ?>" />
    <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/font_kit/stylesheet.css" type="text/css" charset="utf-8" />
    <link rel="shortcut icon" href="<?php bloginfo('template_url'); ?>/favicon.ico" />
    <link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
    <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/jquery.min.js"></script>
    <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/jquery.cycle.all.js"></script>
    <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/jquery-textFill-0.1.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
        $('#slider')
        .after('<div id="controls">')
        .cycle({
            fx: 'fade',
            speed:  2500,
            timeout: 5000,
            pager: '#controls',
            slideExpr: 'a'
        });
    });
    </script>
    <?php if (is_singular() && get_option('thread_comments')) wp_enqueue_script('comment-reply'); ?>
    <?php wp_head(); ?>
</head>
<body>
    <div id="custom_wrapper">
        <div class="header">
            <div class="left">
                <div class="logo"></div>
            </div><!--left-->
            <div class="right">
                <div class="image"></div>
            </div><!--right-->
        </div><!--header-->

        <div class="menu">
            <div class="left"></div>
            <div class="inner" id="menu">
                <?php
                    wp_nav_menu(
                        array(
                            'container_class' => 'menu-header',
                            'theme_location' => '',
                            'menu_id'         => 6,
                            'depth' => 4
                        )
                    );
                ?>
            </div><!--inner-->
            <div class="right"></div>
        </div><!--menu-->
        <div class="clear_10px"></div>

        <?php $single_cat_title = single_cat_title(); ?>
        <?php $p_title = trim(wp_title(NULL, FALSE)); ?>
        <?php $cat = get_the_category(); $c_title = trim($cat[0]->name); ?>

category.php

        <div id="content" class="categories">
            <div class="left border_right">
                <?php if (have_posts()) : ?>
                <?php while(have_posts()) : the_post(); ?>

                    <h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
                    <?php // the_content(); ?>
                    <?php the_excerpt(); ?> 

                    <div class="clear_10px border_bottom"></div>

                    <div class="meta">
                        <?php the_time('F jS, Y') ?>,
                        By <?php the_author_posts_link(); ?>.
                        Filed Under: <?php the_category(', '); ?>
                    </div><!--meta-->

                    <div class="clear">&nbsp;</div>

                <?php endwhile; ?>

                <?php if (  $wp_query->max_num_pages > 1 ) : ?>
                    <div id="nav-below" class="navigation">
                        <div class="nav-previous"><?php next_posts_link(__('&laquo; Older posts', '')); ?></div>
                        <div class="nav-next"><?php previous_posts_link(__('Newer posts &raquo;', '')); ?></div>
                    </div><!-- #nav-below -->
                    <div class="clear">&nbsp;</div>
                <?php endif; ?>

                <?php else : ?>

                    <h2>Nothing Found</h2>
                    <p>Sorry, but you are looking for something that isn't here.</p>
                    <p><a href="<?php echo get_option('home'); ?>">Return to home page</a></p>
                    <div class="clear_10px border_bottom"></div>

                <?php endif; ?>

                <?php if (is_home()) : ?>
                    <div class="check_us_out"></div>
                <?php endif; ?>

                <div class="clear"></div>
            </div><!--left-->

            <div class="right">
                <?php get_sidebar(); ?>
            </div><!--right-->
        </div><!--content-->

<?php get_footer(); ?>

footer.php

        <div class="clear">&nbsp;</div>

    </div><!--custom_wrapper-->

    <div class="footer">
        <div id="custom_wrapper">
            <div class="left">
                <?php get_sidebar('footer'); ?>
            </div><!--left-->
            <div class="right">
                &copy; COPYRIGHT <?php echo date("Y"); ?>, ENKITEC, LP.
            </div><!--right-->
        </div><!--custom_wrapper-->
    </div><!--footer-->
    <?php wp_footer(); ?>

<script type="text/javascript">
    $("#menu ul li ul li:has(ul)").addClass("arrow");
</script>
</body>
</html>

functions.php

<?php
    /* Register a Custom Post Type (Slide) */
    add_action('init', 'slide_init');
    function slide_init() {
        $labels = array(
            'name'                  => _x('Slides', 'post type general name'),
            'singular_name'         => _x('Slide', 'post type singular name'),
            'add_new'               => _x('Add New', 'slide'),
            'add_new_item'          => __('Add New Slide'),
            'edit_item'             => __('Edit Slide'),
            'new_item'              => __('New Slide'),
            'view_item'             => __('View Slide'),
            'search_items'          => __('Search Slides'),
            'not_found'             => __('No slides found'),
            'not_found_in_trash'    => __('No slides found in Trash'), 
            'parent_item_colon'     => '',
            'menu_name'             => 'Slides'
        );
        $args = array(
            'labels'                => $labels,
            'public'                => true,
            'publicly_queryable'    => true,
            'show_ui'               => true, 
            'show_in_menu'          => true, 
            'query_var'             => true,
            'rewrite'               => true,
            'capability_type'       => 'post',
            'has_archive'           => true, 
            'hierarchical'          => false,
            'menu_position'         => null,
            'supports'              => array('title', 'excerpt', 'thumbnail')
        ); 
        register_post_type('slide', $args);
    }

    /* Update Slide Messages */
    add_filter('post_updated_messages', 'slide_updated_messages');
    function slide_updated_messages($messages) {
        global $post, $post_ID;
        $messages['slide'] = array(
            0 => '',
            1 => sprintf(__('Slide updated.'), esc_url(get_permalink($post_ID))),
            2 => __('Custom field updated.'),
            3 => __('Custom field deleted.'),
            4 => __('Slide updated.'),
            5 => isset($_GET['revision']) ? sprintf(__('Slide restored to revision from %s'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
            6 => sprintf(__('Slide published.'), esc_url(get_permalink($post_ID))),
            7 => __('Slide saved.'),
            8 => sprintf(__('Slide submitted.'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))),
            9 => sprintf(__('Slide scheduled for: <strong>%1$s</strong>. '), date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)), esc_url(get_permalink($post_ID))),
            10 => sprintf(__('Slide draft updated.'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))),
        );
        return $messages;
    }

/* Update Slide Help */
add_action('contextual_help', 'slide_help_text', 10, 3);
function slide_help_text($contextual_help, $screen_id, $screen) {
    if ('slide' == $screen->id) {
        $contextual_help =
        '<p>' . __('Things to remember when adding a slide:') . '</p>' .
        '<ul>' .
        '<li>' . __('Give the slide a title. The title will be used as the slide\'s headline.') . '</li>' .
        '<li>' . __('Attach a Featured Image to give the slide its background.') . '</li>' .
        '<li>' . __('Enter text into the Visual or HTML area. The text will appear within each slide during transitions.') . '</li>' .
        '</ul>';
    }
    elseif ('edit-slide' == $screen->id) {
        $contextual_help = '<p>' . __('A list of all slides appears below. To edit a slide, click on the slide\'s title.') . '</p>';
    }
    return $contextual_help;
}
if (function_exists('add_theme_support')) {
    add_theme_support('post-thumbnails');
}


function checkFeild($a) {
    if (trim($a)==""||$a==NULL||empty($a)) {
        return false;
    } else {
        return true;
    }
}

if (function_exists('register_sidebar')) {
    register_sidebar(array(
        'before_widget' => '<div class="block">',
        'after_widget' => '</div><!--block-->',
        'before_title' => '<h1>',
        'after_title' => '</h1>',
    ));
}

function register_my_menus(){
    register_nav_menus(
        array(
            'header-menu'=>__('Header Menu')
        )
    );
}
add_action('init', 'register_my_menus');

function fix_missing_menu($query) {
    $query->set('post_type', array('post', 'nav_menu_item'));
}
add_filter('pre_get_posts', 'fix_missing_menu');
?>
4
  • 1
    Without knowing the code you are using, it's hard to help. Also you should spend some time formatting your question properly.
    – its_me
    Jul 8, 2012 at 1:13
  • i just made some edits, kindly see if its up to the standards. Jul 8, 2012 at 12:47
  • I could not see problem on the page you linked to, so I thought you had solved it already. I’ll reopen the question for now. Good luck.
    – fuxia
    Jul 9, 2012 at 1:20
  • thank you @toscho, and the problem is not solved yet. i still see different menus on category page. Jul 9, 2012 at 12:34

2 Answers 2

1

Don't call Nav Menus by menu_id. Rather, define an explicit theme_location for each place in your Theme template at which you want to include a Nav Menu, and then use that theme_location as the parameter passed to wp_nav_menu().

In this case, you've defined a header-menu Theme location, so change this:

<?php
 wp_nav_menu(
        array(
            'container_class' => 'menu-header',
            'theme_location' => '',
            'menu_id'         => 6,
            'depth' => 4
        )
    );
?>

...to this:

<?php
 wp_nav_menu(
        array(
            'container_class' => 'menu-header',
            'theme_location' => 'header-menu',
            'depth' => 4
        )
    );
?>

Also: your pasted category.php code omits get_header(). Please verify that you are calling get_header() in category.php.

3
  • thanks @chip-bennett, the comments you posted is very useful, but i have already solved the problem. Nov 29, 2012 at 19:15
  • @ZainBaloch so: what was the solution? Nov 29, 2012 at 19:16
  • the solution was similar to what you've described above. i gave theme_location to the menu and it worked :) Dec 1, 2012 at 17:19
0

Look at the source code of both pages, on home page I can see "Menu Item" class assigned to 'LI element' while on category page it is "page item" that means your menu is working fine on home mage but on category page something went wrong and the default fall back menu - 'wp_page_menu' appeared.

Try disabling the fallback by adding another parameter to array - 'fallback_cb' => false, and see if works.

1
  • thank you for the reply @amit, do you mean something like this: <?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary', 'menu' => 'Menu', 'fallback_cb' => false, 'depth' => 4 ) ); ?> than i have already disabled fallback_cb in my header. Jul 11, 2012 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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