0

I am seeking two codes which I haven't been able to find which would allow a child menu to be created in a sidebar.

A code to display the sub-categories of the parent category.

A code to display the sub-pages of the current page.

I remember having a theme that had these codes implemented which also allowed styling to be applied to current categories. Maybe it has since been depreceated and maybe not - but I would sure appreciate if anybody had more information on these codes.

1

for sub-pages of current page check wp_list_pages()

<?php 
  $page_id = get_the_ID();
  wp_list_pages( array( 'child_of'=>$page_id ) );
?> 

and for sub-categories of the parent category check wp_list_categories()

<?php 
$cat_id = get_query_var('cat');
if( !empty($cat_id) ) {
  wp_list_categories( array( 'child_of'=> $cat_id ) );
}
?>

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.