• Here is a code I am using to display a menu with 2 different link styles.
    First style is used if menu link points to the current page (page where we are located).
    Second style is used if menu link points to any other page.

    foreach($pages as $page)
    {
    $option = '<li id="notcurrent"><a href="./?page_id='. $page->ID . '">' . $page->post_title . '</a></li>';
    $option2 = '<li id="current"><a href="./?page_id='. $page->ID . '">' . $page->post_title . '</a></li>';
    
    if (is_page($page))
    {
    echo $option2;
    }
     else
    {
    echo $option;
    } 
    
    }

    I have a problem with this code:
    When 2 different pages have same name (which may occur), they both display with the same “current style”.
    How can I change this code to make it work even with pages with same names (but different ids)?

Viewing 3 replies - 1 through 3 (of 3 total)
  • you can use the is_page function and pass it just the id:

    if (is_page($page->ID)){
     [...]
    Thread Starter tomasi514

    (@tomasi514)

    All right jceresini ??
    Seams very simple!
    I am gonna try it, thanks!

    Thread Starter tomasi514

    (@tomasi514)

    Seams to work fine but I still have some troubles with my menu, you can check it here.
    See? On this page, Virtual Learning and Immigration link are both highlighted while Virtual Learning only should be.

    Different page ids, different names, any explanation?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How can I make condition: if menu link’s id == current page id?’ is closed to new replies.