WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Highlight current page on sidebar's menu list (1 post)

  1. theredborough
    Member
    Posted 11 months ago #

    Hi! I know that if I'll use <?php wp_list_pages(); ?> that I'll have a current_page_item class. But I also need to display a custom field value called "category" so I opted not to use wp_list_pages.

    Anyway, I added a menu list on my sidebar where it features the child pages for let say "Articles". I would to be able to highlight the "active page" on the menu list. I was thinking of adding some variable like $current_page = so I can add a class and use that in my CSS. I just don't know where I should put it. Also I'm not using sidebar widgets - if that's a useful information for you guys.

    I'm a little new in WordPress.

    Here is the code I used:

    <div class="posts">
    	<?php
    	 $parent_id = get_post(44);
    
    	$args = array(
    	'post_type' => 'page',
    	'posts_per_page' => -1,
    	'post_parent' => $parent_id->ID,
    	'order' => 'ASC',
    	'orderby' => 'menu_order'
    	);
    
    	$parent = new WP_Query ( $args );
    
    	if ($parent->have_posts () ) :
            ?>
    
           <ul>
    
    	  <?php while ($parent->have_posts()): $parent->the_post(); ?>
    
                      <a href="<?php the_permalink(); ?>">
    			 <li>
    				 <h4><?php the_title(); ?></h4>
    				 <h6><?php echo get_post_meta($post->ID, "category", true); ?></h6>
    			 </li>
    		 </a>
    
    	 <?php endwhile; ?>
    
    	<?php endif; wp_reset_query(); ?>	
    
          </ul>
    </div>

    Thank you in advance!

Reply

You must log in to post.

About this Topic