$10
Create a short code that list child pages of active page
The question: How do I create a short code that list child pages of active page?
The Scope: Create a short code function that can be called from within the WYSIWYG wp editor on a page, that lists the sub/child pages for that active page. It should display them as links, or better yet an unordered list of links to the pages.
I've referenced both of these:
Get Pages Function
List Pages Function
But neither seem to do what I am looking for, please help.
Aaron | 03/10/10 at 4:41am
| Edit
(2) Possible Answers Submitted...
-

Last edited:
03/10/10
5:03amColin Pool says:I think this plugin is what you need: http://wordpress.org/extend/plugins/wordpress-navigation-list-plugin-navt/
It makes custom navigation lists. You can change everything you want in the css and you can select the paged you want to show each list.- 03/10/10 5:08am
Aaron says:Sorry, forgot to mention the solution shouldnt be a third-party plugin... looking for a piece of code :)
Thanks - 03/10/10 5:17am
Colin Pool says:
First you need to enable PHP in you're pages before you can put PHP code into pages with the editor.
You can enable this with a plugin.
Then you put this code in the html editor of the page:
<ul>
<?php
global $id;
wp_list_pages("title_li=&child_of=$id&show_date=modified
&date_format=$date_format"); ?>
</ul>
If I get you right then this is the code you need.
- 03/10/10 5:08am
-

Last edited:
03/10/10
5:34amBen Huson says:There's also this one:
http://wordpress.org/extend/plugins/list-pages-shortcode/Previous versions of this answer: 03/10/10 at 5:08am | 03/10/10 at 5:08am
- 03/10/10 5:08am
Aaron says:Sorry, forgot to mention the solution shouldnt be a third-party plugin... looking for a piece of code :)
Thanks - 03/10/10 5:11am
Ben Huson says:In theory those plugins should be GPL licensed which means the code is available for you use and modify. The code is actually very simple just download the List Pages Shortcode plugin, take a look and you'll see.
- 03/10/10 5:18am
Ben Huson says:In it's most basic form, the code should look like this:
function shortcode_child_pages( $atts, $content ) {
global $post;
$output = wp_list_pages( array( 'child_of' => $post->ID ) );
if ( !empty( $output ) ) {
$output = '<ul class="child-pages">' . $output . '</ul>';
}
return $output;
}
add_shortcode( 'childpages', 'shortcode_child_pages' );
Then use the shortcode [childpages] - 03/10/10 5:24am
Aaron says:This is more along the lines of what I'm looking for but without it displaying the heading 'Pages' and why does it place the links at the top of the post content even if I'm calling the short tag in the middle of the content in the WYSIWYG?
- 03/10/10 5:28am
Ben Huson says:Just change the parameters for wp_list_pages:
$output = wp_list_pages( array( 'child_of' => $post->ID, 'title_li' => '', 'echo' => 0 ) );
- 03/10/10 5:34am
Aaron says:Thanks!
- 03/10/10 5:08am
This question has expired.
Current status of this question: Completed





