Adam
Adam

Reputation: 1459

how to list subpages in sidebar without widget - wordpress

I am trying to create a list of subpages of a parent page, which will appear in the sidebar of my wordpress site. This sidebar will appear on every page.

So for example, I have a page with an ID of 54. This page has 7 subpages. I would like to display these 7 pages in the sidebar (just the titles), as well as any more subpages that get added.

There is a currently a widget called 'Pages' that will do this, but I would like to do this via code directly in the sidebar.php rather than using a widget as there are a few constraints with using the widget.

Any help would be greatly appreciated.

Thanks

Upvotes: 0

Views: 1465

Answers (2)

Aky Joe
Aky Joe

Reputation: 271

To write custom code for such purpose will require you to execute php inside the widget. Try using this Php Code Execute Plugin

Upvotes: 0

ccov77
ccov77

Reputation: 791

Try this link: http://codex.wordpress.org/Function_Reference/wp_list_pages Specifically, look the 'depth' and 'child_of' parameters for the function.

Should be:

<?php wp_list_pages( array( 'depth' => 1, 'child_of' => YOUR_PAGE_ID_HERE ); ?> 

furthermore, you can get the page id dynamically too of course.

Upvotes: 4

Related Questions