How can I make condition: if menu link’s id == current page id?
-
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)
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.