I am looking to use the wp_list_pages function to show children pages of a specific page ID. I was able to do this easily, but now I found an issue with it. I am running a WordPress network of sites (total of 8). I am trying to set this up where I will only need 2 theme folders because there are 2 main blogs with 3 sub sites that fall under each. So, I am trying to make as many dynamic calls in my theme files as possible to prevent duplicating themes for each site.
In my sidebar I am using the following code:
<ul>
<?
wp_list_pages('orderby=name&depth=1&order=DESC&show_count=0&child_of=10&title_li=');
?>
</ul>
The issue I am running in to is, on each of the sub sites the page ID’s have changed but my sitemap for the most part has not. So on my main site child_of=10 displays the proper sub pages in my sidebar, but in my sub-sites the child_of=10 is a different page so I am not getting the proper child pages to display. I had a similar issue with pulling in posts but I was able to do the following:
<?
$category = get_category_by_slug('news');
wp_list_categories('orderby=name&order=DESC&show_count=0&exclude=53&title_li=&child_of='.$category->term_id);
?>
I am trying to achieve a similar solution for wp_list_pages where I use a page slug to identify the child pages instead of the page ID. Been digging around and trying a few posts I have found on Google / here but no luck. Hoping someone can help me out.
Why don’t you use
get_page_by_title()
to get the page object, and then pass its ID as the child_of parameter?If you would rather use the actual slug, then
get_page_by_path( $slug )
should do the trick.So: