• Apr
  • 19
  • 2012

How to show current page’s subpages in sidebar?

This question is most searched question in google. It is being used highly in wordpress to list the subpage’s of current page in the sidebar.

We have made it simple for you. Its very easy. Just write down the below code in the sidebar.

Show Subpages menu if it exists in sidebar, and in subpages show parent page’s title.if menu is not there it should not show anythig.

if(wp_list_pages('child_of='.$post->ID.'&echo=0') || $post->post_parent!=0 ) {

$page_title=$post->post_title;
$page_id=$post->ID;
$page_parent=$post->post_parent;

if($post->post_parent!=0)
{
$args=array(
'child_of'=>$page_parent,
'orderby'=>'menu_order',
'order'=>'ASC',
'title_li'=>'',
);
} else {
$args=array(
'child_of'=>$page_id,
'orderby'=>'menu_order',
'order'=>'ASC',
'title_li'=>'',
);
}

if($page_parent==0)
{
$sliderID = $post->ID;
} else {
$sliderID = $post->post_parent;
}

?>

This code will show subpages when either parent page or sub page is active.

You can also customize code more as per your requirement by passing the different arguments($args).

Ravi Makhija

Ravi Makhija

A writer, an Entrepreneur. Curious about the internet of everything. Interested in the cutting edge landscape of mobile apps and SAAS products. Blogs for Guru Technolabs - A Mobile App Development Company.

Let's Discuss a Project

Please share your unique idea or project requirement with us, our business concern person will get back to you with further details.