• Hey,

    So I was wondering if it’s possible to set the current_page_item with an if statement or some other kind of php when you are viewing a post? I have a feeling it’s possible but when I tried

    <?php $page_id=36; ?><?php if(get_page($page_id)) echo ' class="current_page_item"'; ?>

    but it doesn’t do anything. Help?

Viewing 2 replies - 1 through 2 (of 2 total)
  • what code is the menu using?

    what are you expecting your code to do?

    I read the code this way:
    if you have a page with the ID 36 in your site, then output the text.

    Thread Starter technodude95

    (@technodude95)

    Okay, so basically, the nav bar looks like it’s using wp_nav_menu, but im not positive. What I do know is that it is dynamically generating the pages in the nav bar:

    <?php if ( function_exists('wp_nav_menu') ):?>
    				<?php wp_nav_menu( array( 'show_home' => 'Home','container' => 'globalNavi', 'theme_location' => 'primary') ); ?>
    			<?php else: ?>
    				<?php wp_page_menu( array( 'show_home' => 'Home', 'sort_column' => 'menu_order' ) ); ?>
    			<?php endif; ?>

    The problem right now is that I need it to use current_page_item on a post. I want it to check what category the post is, figure out which page id that translates to, and then highlight the page in the nav bar with current_page_item.

    Because basically, I have different pages that have feeds of different categories. If I am on the category ‘Phones’ and click a post from within the category or the page, I still need the corresponding page highlighted on the nav bar.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘current_page_item Set with if-statement’ is closed to new replies.