How to detect the page you’re currently viewing?
-
Hi, hope someone can help me with this.
I’m coding a loop to bring in page titles as a menu, using the following loop:
<?php $curr = ''; $menuitems = get_pages('sort_column=menu_order&sort_order=ASC'); foreach ($menuitems as $menuitem) { $menu = '<li class="tabstart '.$curr.'"></li>'; $menu .= '<li class="tabmid '.$curr.'"><a href="'.get_page_link($menuitem->ID).'">'; $menu .= $menuitem->post_title; $menu .= '</a></li>'; $menu .= '<li class="tabend '.$curr.'"></li>'; echo $menu; } ?>
As you can see above there is a variable called $curr. This stands for “current” and there is a CSS class called current which changes the colour of the tab of the page you’re viewing. What I need to know is, is there a function or some kind of way of detecting which page the user is viewing in order to populate the $curr variable with the word “current” on the current page but remain empty for every other?
I’m quite new to WordPress coding so any help is appreciated, thank you.
Michael
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘How to detect the page you’re currently viewing?’ is closed to new replies.