My WP site is [[LINK href="http://www.pavement.biz"]]here[[/LINK]].
My parent page “Directory” is [[LINK href="http://www.pavement.biz/?page_id=15"]]here[[/LINK]].
I want the “Directory” page to automatically include links to all the child pages as shown in the right hand side bar,
i.e.
• Airfield Pavements
• Asphalt Modifiers and Binders
• Asphalt Technology
• Etc.
I have looked at various posts on forums, for example:
[[LINK href="http://wordpress.org/support/topic/337703"]]http://wordpress.org/support/topic/337703[[/LINK]] and
[[LINK href="http://codex.wordpress.org/Template_Tags/wp_list_pages#List_Sub-Pages"]]http://codex.wordpress.org/Template_Tags/wp_list_pages#List_Sub-Pages[[/LINK]]
But whenever I attempt to put any of that code into my Page via the HTML tab, the resulting page just shows the code.
Do I need to install a plugin like Exec-PHP to enable code to be executed?
Regards,
Leigh
wjm answers:
Hi Leigh,
There are three possible ways i can think of.
1) install Exec PHP and include the php code in the content of the page.
2) add a filter to the_content() to that page. I can write the code if you want this solution.
or
3) create a template and apply it to that page. Which is the one i recommend
I have created this tempalte using page.php (from twentyten, the default wordpress theme), but you can create your own copying and pasting the code.
save the following file
http://wordpress.pastebin.com/dLp5XpYy
as subpages.php and save it in your theme directory.
Then go and edit the directory page in wp-admin, and on the right side bar, in the "Page Attributes" box, under "Template" select the tempalte "List Subpages"
I dont know what theme you are using, but you can just make a copy of page.php and rename it subpages.php, and right after "the_content()" put this code
<?php
//LIST SUBPAGES [START]
echo '<ul class="xoxo pages">';
wp_list_pages( array( 'title_li' => false, 'parent' => $post->ID ) );
echo '</ul><!-- .xoxo .pages -->';
//LIST SUBPAGES [END]
?>
I recommend using the tempaltes because you can apply it to how many pages you want, and using a filter, you will have to edit your functions.php file every time you want to add this feature to a new page.
let me know if it works, and if you have any further question
-wjm
Leigh Wardle comments:
Hi wjm,
I am implementing your 3rd. option.
I have saved the following file
http://wordpress.pastebin.com/dLp5XpYy
as subpages.php and saved it to my theme directory.
But when I edit the directory page in wp-admin, in the "Page Attributes" box, under "Template", there is no template "List Subpages", only the 3 standard choices.
Regards,
Leigh
wjm comments:
try removing,
* @package WordPress
* @subpackage Twenty_Ten
* @since Twenty Ten 1.0
I am looking into it,
which WordPress version are you running?
wjm comments:
better, do this,
remove all the initial comments, and leave
/*
* Template Name: ListSubpages
*/
wjm comments:
Leight:
Done
the problem was that when i said save subpages.php to your theme's folder, i meant to to themes/YOURTHEMENAME/ folder.
so i moved it to
/wp-content/themes/neuticaplus/
also, i used thematic's page.php as the base for this template. so it looks the same as any other page.
wjm comments:
And to keep the openess of this site:
if anybody else wants this template, here's the template for Thematic.
http://wordpress.pastebin.com/QR28D2GW
Lew Ayotte answers:
Yeah, you can't use the HTML tab in the page to do this... you'll either need to add the code into the page.php theme file or install the php code widget (http://wordpress.org/extend/plugins/php-code-widget/) and use the widget for the sidebar.
I like PHP Code widget better than Exec-PHP, just a personal preference.
Do you need help generating the php code?
EDIT: Also, depending on your theme (and your desire), you could put the code in the sidebar.php filel
Leigh Wardle comments:
Hi Lew,
On your advice I will try the PHP Code widget.
But how do get that widget working on the my parent page “Directory”?
P.S. I do not want to change my sidebar - I am happy with it as it is.
Regards,
Leigh
Lew Ayotte comments:
WJM's solution will probably be the best for what you need.
Lew
Pippin Williamson answers:
Use this plugin:
http://wordpress.org/extend/plugins/list-pages-shortcode/
It should do everything you need. Place the [child-pages] shortcode into a text widget.
Leigh Wardle comments:
Hi Pippin,
I just put [child-pages depth="1"] in the Page content and [[LINK href="http://www.pavement.biz/?page_id=15"]]here[[/LINK]] is what I get.
It looks good to me - is that what I should be expecting?
Regards,
Leigh
Pippin Williamson comments:
Leigh, that's exactly what it was supposed to do. You may also put the list in the side bar if you wish by placing [child-pages depth="1"] inside of a text widget to display the child pages of which ever page you are on. Or, do as you have done and enter the shortcode directly into each page you wish to list the cild pages.
If you're interested, for a small amount more, I can show you how to create another custom sidebar that would allow you to place widgets into the main-body of your pages, allowing you to list the child pages with the shortcode through a widget so that you don't have to enter manually put the short code into each page.