Fix Simple PHP Wordpress Page Depth Function

I have created a php function to expand upon the basic wp_list_pages function. But to do it I needed to find out a pages depth, I figured out how to do it on a single page, but when I send it do the custom list pages function it just returns zero for the pages being sent to it.

I use this within the wordpress page:


And these functions

function pagedepth($page)


$ancestors = get_post_ancestors($page->ID);

return count($ancestors);


function listpoint($pg)


echo '<li><a href="';

echo get_page_link($pg->ID);

echo '">';

echo $pg->post_title;

echo '</a><small> ';

echo get_userdata($pg->post_author)->display_name;

echo '&#151;';

if (get_post_custom_values('Character', $pg->ID)==TRUE)


$mykey_values = get_post_custom_values('Character', $pg->ID);

foreach ( $mykey_values as $key => $value )


echo $value;

echo ', ';



echo mysql2date('D, M j, Y H:i a', $pg->post_date);

echo '</small></li>';


function listpages($thepost)


echo '<ul>';

$pages = get_pages('child_of='.$thepost->ID.'&sort_column=post_date&sort_order=DESC');

$previousdepth = 0;

$homedepth = pagedepth($thepost);

foreach($pages as $page)


$pagedepth = pagedepth($page);

if($pagedepth > $previousdepth)

echo '<ul>';

while($pagedepth < $previousdepth && count(get_pages('child_of='.$page->ID)) != 0)

{ echo '</ul>';


if($pagedepth == 1)



$parent_page = $page->post_parent;

$content = $page->post_content;



$content = apply_filters('the_content', $content);


$previousdepth = $pagedepth;



First solution gets paid $30 immediately. If done well and good I there will be more work down the track.

Beceriler: PHP, WordPress

Daha fazlasını gör: wordpress get_pages depth, wordpress page depth, get_pages depth, wordpress pages depth, php pg, li.be, li-be, depth first, page depth wordpress, get_pages wordpress depth, get_post_ancestors get_pages, wordpress depth php, simple function php wordpress, find page depth wordpress, php page depth, wordpress list pages depth, wordpress page, wordpress basic, PHP WORDPRESS, php function , php / wordpress, php -wordpress, pg, desc, simple continue

İşveren Hakkında:
( 7 değerlendirme ) Alexandria, Australia

Proje NO: #693599



Ready to start. Check PM :)

1 gün içinde %selectedBids___i_sum_sub_4%%project_currencyDetails_sign_sub_5% USD
(3 Değerlendirme)

2 freelancers are bidding on average $30 for this job


let's start please see PMB for more details...

in %bids___i_period_sub_35% gün içinde30%project_currencyDetails_sign_sub_37% %project_currencyDetails_code_sub_38%
(82 Değerlendirme)