Home > Development > Wordpress > Sub-page Count > Version 0.1β

This is a beta version, so there are bound to be a few bugs.

Requires: Wordpress Version 2.0-2.3 (not compatable with 2.5+)

<?php
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0&depth=1&sort_order=asc');
if ($children) { ?>
<ul>
<?php
preg_match_all('#<li class="page_item page-item-(.*?)">#msi', $children, $childrenIDs);
 
$count   = count(explode("\n", $children));
$match   = array($count);
$replace = array($count);
 
foreach($childrenIDs[1] as &$child){
	$count2    = count(explode("\n", wp_list_pages('title_li=&child_of='.$child.'&echo=0&depth=1&sort_order=desc'))) - 1;
	$match[]   = '#<li class="page_item page-item-'.$child.'"><a href="(.*?)" title="(.*?)">(.*?)</a></li>#msi';
	$replace[] = '<li class="page_item page-item-'.$child.'"><a href="$1" title="$2">$3 ('.$count2.')</a</li>';
}
 
$children = @preg_replace($match, $replace, $children);
 
echo $children;
?>
</ul>
<?php
}
?>

Comments

You must be logged in to post a comment.