Forums

[resolved] current_page_item not displaying using wp_list_pages (4 posts)

  1. josepaitamala
    Member
    Posted 5 months ago #

    Hello,

    I have used this code here:

    <?php
    if(!$post->post_parent){
    	// will display the subpages of this top level page
    	$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
    }else{
    	// diplays only the subpages of parent level
    	//$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
    
    	if($post->ancestors)
    	{
    		// now you can get the the top ID of this page
    		// wp is putting the ids DESC, thats why the top level ID is the last one
    		$ancestors = end($post->ancestors);
    		$children = wp_list_pages("title_li=&child_of=".$ancestors."&echo=0");
    		// you will always get the whole subpages list
    	}
    }
    
    if ($children) { ?>
    <div id="sub-pages-sidebar">
    	<ul>
    		<?php echo $children; ?>
    	</ul>
    </div>
    <?php } ?>

    to display the subpage of a page on the sidebar, on this website I did before is displays all fine with a selected class http://www.colchesteryogastudio.co.uk/yoga-classes/parent-baby-yoga/
    but, on this other website I have done
    http://new.simplydesign.co.uk/services/web-development/
    the current_page_item class is not displaying.

    Can anyone help please? Thank you

  2. keesiemeijer
    moderator
    Posted 5 months ago #

    There is likely some code in the main template which alters the query_string;

    try to put <?php wp_reset_query(); ?> before your code.

  3. josepaitamala
    Member
    Posted 5 months ago #

    Hey that fixed it! the current_page_item appears now, thank you very much!

  4. keesiemeijer
    moderator
    Posted 5 months ago #

    No problem, glad you got it resolved.

Reply

You must log in to post.

About this Topic