Title: Adding &quot;current&quot; class if using get_pages
Last modified: August 19, 2016

---

# Adding "current" class if using get_pages

 *  Resolved [Richard Archambault](https://wordpress.org/support/users/richardmtl/)
 * (@richardmtl)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/adding-current-class-if-using-get_pages/)
 * Hello!
 * For my particular site and for several reasons, I can’t use wp_list_pages for
   a nav menu in part of my theme. So I use the following code instead:
 *     ```
       <ul>
       <li>
       <?php $parent_link = get_permalink($post->post_parent); ?>
       <a href="<?php echo $parent_link; ?>"><?php $parent_title = get_the_title($post->post_parent); echo $parent_title; ?></a></li>
   
       <?php 
   
       $mypages = get_pages('child_of='.$post->post_parent.'&sort_column=menu_order&hierarchical=0');
   
       	if($mypages)
       	{
       		foreach($mypages as $page)
       		{
       	?>
       	<li>
       	<a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a>  </li>
   
       	<?php
       		}
       	}
       ?>
       </ul>
       ```
   
 * How do I add a “current” class for the page that I’m currently on? I figure I
   could do it using some jquery or something (not sure, but I imagine I could),
   but I’d like to do it in the php if at all possible. Can someone give me a hand?
   Maybe something I need to add in my functions.php? Or do I keep it in this template?
   I imagine that it’d be through a simple IF statement right inside the href where
   I echo the page link, but I’m not quite sure how to do it.
 * Thanks!

Viewing 1 replies (of 1 total)

 *  Thread Starter [Richard Archambault](https://wordpress.org/support/users/richardmtl/)
 * (@richardmtl)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/adding-current-class-if-using-get_pages/#post-1945064)
 * Got it!
 *     ```
       <?php
       $current_id = get_the_ID();
       $mypages = get_pages('child_of='.$post->post_parent.'&sort_column=menu_order&hierarchical=0');
   
       	if($mypages)
       	{
       		foreach($mypages as $page)
       		{
       		$link_page_id = ($page->ID)
       	?>
   
       <li>
       	<a <?php if ($current_id == $link_page_id) : ?> class="current" <?php else : ?><?php endif; ?>class="current" <?php else : ?><?php endif; ?> href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a>
   
       </li>
       	<?php
       		}
       	}
       ?>
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Adding "current" class if using get_pages’ is closed to new replies.

## Tags

 * [class](https://wordpress.org/support/topic-tag/class/)
 * [get_pages](https://wordpress.org/support/topic-tag/get_pages/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [Richard Archambault](https://wordpress.org/support/users/richardmtl/)
 * Last activity: [15 years, 3 months ago](https://wordpress.org/support/topic/adding-current-class-if-using-get_pages/#post-1945064)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
