Last active
December 22, 2015 00:39
-
-
Save neilff/6390771 to your computer and use it in GitHub Desktop.
Wordpress Sitemap: Recursive Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* check_for_children | |
* | |
* This recursive function retrieves all the sitemap pages, it calls itself | |
* until the children pages for that node are exhausted | |
* | |
*/ | |
function check_for_children( $region_id, $children, $type = 1 ) { | |
if ( count($children) > 0 ) { | |
echo '<ul class="children">'; | |
foreach ($children as $child) { | |
// Check if page is supposed to show in the sitemap or not | |
$meta = get_post_meta($child -> ID, 'wpcf-visible-in-sitemap'); | |
if ( $meta[0] != 1 ) { | |
echo '<li><a href="' . get_permalink($child -> ID) . '" alt="Link to: ' . $child -> post_title . '">' . $child -> post_title . '</a></li>'; | |
$children = get_posts( array('category' => $region_id, 'post_type' => 'page', 'numberposts' => 100, 'post_parent' => $child -> ID, 'post_status' => 'publish', 'orderby' => 'menu_order', 'order' => 'ASC') ); | |
check_for_children($region_id, $children); | |
} | |
} | |
echo '</ul>'; | |
} else { | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment