I’m creating quite a complex site based on the Wordpress framework and I have run into a problem that I cannot seem to solve…
My site http://icomprintmanagement.co.uk.s88828.gridserver.com/healthcare/ has a section toward the bottom which holds lots of Parent page categories, (i.e accident & emergency is the parent page and there are several children within it) and nested within them are product pages, what I’m trying to do is specify the page and pull all the product pages into a list. Currently I have tried to do it on the first product Category “medical Records” using the following PHP:
I think your code is correct, but you are using this code: $post->ID which will grab the current post id.
If you want to display all of the children under a certain page, you have to use the correct page id. You can get the page id from the admin by editing the page and it should be the number at the end of the url. That is what you need to put in place of the $post->ID value.
From the source you showed I take it you manually create the Parent link.
I’m assuming the title of the Medical Records page is named “Medical Records”.
It’s not the children of the current page that are being pulled.
I request the information for a particular page, in this case the page with the title “Medical Records”.
The only difference between my code and yours is that you don’t have to hard code the page ID. I think it would make the code a bit more readable and you can create a loop to build the overview.
Oh duh. I didn’t take a close enough look at the code you provided.
But wouldn’t it be better to use the page id, since the page id is not going to change? My concern would be if the page title changed, then your code wouldn’t work.
With this idea, this is how I would code it (using your code):
// The parents titles you want to show
$page_id = array (15, 23); // the page ids of Medical Records and Finances
foreach ( $page_id as $current_pageid ) {
$page = get_page( $title );
$url = get_permalink( $current_pageid );
echo '<div class="grid_2 productColumn">';
echo '<h2>';
echo '<a href=' . $url . ' title=' . $page->post_title . '">' . $page->post_title . '</a>';
echo '</h2>';
$children = wp_list_pages( 'title_li=&child_of=' . $current_pageid . '&echo=1' );
if ( $children ) {
echo '<ul>';
echo $children;
echo '</ul>';
}
echo '</div><!-- End of product Column 1Div -->';
}
I’m not 100% sure this would work because I haven’t tested the code. Does…thanks for the improved code.
@does: yes ideally what I would like to do is pull the whole overview via a loop so that that section is automated depending on what categories I set up in the control panel. Then within each category the children would also be automated as your solution above is trying to do.
So to recap, The area at the bottom of the page has 12 main category pages, i.e “medical records” being one of the 12. Within that category (and every other) I would like it to display the children in a list related to that category. I would like the whole process to be automated so that If I decided to change the name of one of the parent category pages from say “medical records” to “medical Files” in the back end then it would change in the area at the bottom of the page. And like wise for the children pages within each Main parent.
Hi Both, Sorry to revisit this, but I have noticed that the code you gave me works great but it is not validating.
According to W3c Validator the lists that are being created are being displayed without the <ul></ul> tags wrapped around the list items…
the error I get is:
# Error Line 352, Column 36: document type does not allow element "li" here; missing one of "ul", "ol", "menu", "dir" start-tag
<li class="page_item page-item-179"><a href="http://icomprintmanagement.co.uk.s…
The mentioned element is not allowed to appear in the context in which you’ve placed it; the other mentioned elements are the only ones that are both allowed there and can contain the element mentioned. This might mean that you need a containing element, or possibly that you’ve forgotten to close a previous element.
One possible cause for this message is that you have attempted to put a block-level element (such as “<p>” or “<table>”) inside an inline element (such as “<a>”, “<span>”, or “<font>”).
The code echo’s out the <ul> tags before and after the li items but for some reason they do not show up in the page when it is brought from the server…
if you view the source of the following page you will see what I mean,