例子 :
About
--- technical
--- medical
--- historical
--- geographical
--- political
如何创建这样的函数?
function get_child_pages_by_parent_title($title)
{
// the code goes here
}
并像这样调用它,这将返回一个充满对象的数组。
$children = get_child_pages_by_parent_title('About');
你可以使用这个,它确实适用于页面ID而不是标题,如果你确实需要页面标题,我可以修复它,但ID更稳定。
<?php
function get_child_pages_by_parent_title($pageId,$limit = -1)
{
// needed to use $post
global $post;
// used to store the result
$pages = array();
// What to select
$args = array(
'post_type' => 'page',
'post_parent' => $pageId,
'posts_per_page' => $limit
);
$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ) {
$the_query->the_post();
$pages[] = $post;
}
wp_reset_postdata();
return $pages;
}
$result = get_child_pages_by_parent_title(12);
?>
这一切都记录在这里:
http://codex.wordpress.org/Class_Reference/WP_Query http://codex.wordpress.org/Class_Reference/WP_Query
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)