I have a parent page with child pages. How to get child pages and add unique class only to active page ? I am making a sidebar with children's menu parent page one level up.

I can list all child pages but i have problem to add an unique class to active child page to css differently.

global $post;
$direct_parent = $post->post_parent;
$args = array(
'post_type'      => 'page',
'posts_per_page' => -1,
'post_parent'    => $direct_parent, 
'order'          => 'ASC',
'orderby'        => 'menu_order'

$parent = new WP_Query( $args );

if ( $parent->have_posts() ) : ?>

<ul class='sidebar-list'>

<?php while ( $parent->have_posts() ) : $parent->the_post();
<a href="<?php the_permalink()?>">
<?php the_title(); ?>
<?php endwhile; ?>


<?php endif; wp_reset_query(); ?>

I made this by jQuery:

$('.sidebar-list li a').filter(function(){
  return this.href === location.href;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.