trejder
Member
Posted 1 month ago #
Hi there,
I'm constructing a WP-based blog that contains many information on pages instaead of post, layed in a nice layout of pages and subpages. Is it possible (and how to achieve it - by modifying theme PHP code or using some function) to list all subpages belonging to current page when this page is displayed?
For example, I have:
- Info
-- About
-- Contact
- My works
-- Photo
-- WWW
Info and My works are empty now as they are only placeholders for subpages. I would like to list About and Contact when user select Info and Photo and WWW when displays My works.
Of course I can add each new subpage manually on its ancestor page. But in fact I forgot about it most of the time and think that this could be somehow automated?
Regards,
Trejder
One possibility is the plugin http://wordpress.org/extend/plugins/template-tag-shortcodes/ along with the shortcode:
[wp_list_pages]
Or you would need to use the template tag, wp_list_pages() in a Page template.
In either case you will use the child_of=x argument.
scotchegg78
Member
Posted 1 month ago #
uck plugins for this :)
Get your hands dirty ...
use this code in your theme file...
<div id="submenu">
<ul>
<?php
if($post->post_parent)
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
else
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
if ($children) { ?>
<?php echo $children; ?>
<?php } ?>
</ul>
</div>
trejder
Member
Posted 1 month ago #
scotchegg78,
The solution you've provided works perfectly except for the fact that it only displays subpages titles as link to them. How to modify above code to have actually displayed title and lead (part of each page before pressing "Insert read more tag) - text that in post is displayed before "Read more" link?
Look at using Function_Reference/get_pages <---there's examples in that article.
@MichaelH:
I'd love to use that plugin, but this short code: [wp_list_pages] lists all pages, not only the subpages of the current page...