[英]How to get the number of sub-page/child pages that exist in Wordpress?
基本上,我试图在特定父页面的每个子页面中显示类似“查看TotalNumberOfPages的PageNumber”的内容。 所以我试图弄清楚如何计算存在的子页面/子页面的数量并将其显示在子页面上?
以Calle的答案为基础。
//get the sub pages for the parent page
$subPages = get_pages('child_of'=>parent_page_id);
//$i will equal the page number
$i=1;
foreach($subPages as $subs){
//not sure what the exact array key for page_id will be. use var_dump($subPages)to find out
//make the array key the page id for use later (as current_page_id)
$pageNumber[$subs->page_id] = $i;
}
$numberPages = count($pageNumbers);
然后显示您所在页面的页数和页码。
echo 'vewing page '.$pageNumber[current_page_id].' of '.$numberPages;
您可以使用count(get_pages('child_of'=> page_id))来获取子页面数。 但是为了显示第2/5页,您必须在某处定义哪个子页面是哪个数字。 我建议您在自定义字段中执行此操作。 只需将1、2、3、4、5分别放在您拨打电话或其他号码的每个页面的自定义字段中即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.