[wp-hackers] what is the best (fastest) way to check if a page
has children?
Viper007Bond
viper at viper007bond.com
Mon Mar 31 02:37:12 GMT 2008
Something along the lines of this will probably work:
if ( !empty( wp_list_pages( 'echo=0&child_of=' . $post->ID . 'title_li=' ) )
) $children = TRUE;
Similiar code in action: http://www.viper007bond.com/about/
Source:
http://www.viper007bond.com/wordpress/wp-content/themes/neat_1024/page-listchildren.phps
It doesn't check for children as I manually assign the Page template, but it
still should give you some ideas.
On Sun, Mar 30, 2008 at 11:36 AM, André Schieleit <
wphackerslist at anschitech.de> wrote:
> Hi,
>
> I searched the internet, but found no simple/fast solution.
> I want to check if a page has sub-pages to prevent some html being
> displayed.
> I have a homemade theme, where I used this line that worked well up
> to WP 2.3.3:
>
> if(get_page_children($myid, $pages)) :
>
> $myid is populated with the ID of the current page. $pages is empty.
>
> With WP 2.5 I encounter this error:
> Warning: Invalid argument supplied for foreach() in /[server_path]/wp-
> includes/post.php on line 1783
>
> So it seems to me, that there has something changed in 2.5 that
> causes the failure.
> Is there any wordpress function that provides only the information
> that a page has children with no unnecessary overhead? I do not want
> to rely on a plugin for my theme to work.
>
> Best Regards,
> André_______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
--
Viper007Bond | http://www.viper007bond.com/ | http://www.finalgear.com/
More information about the wp-hackers
mailing list