如何获取Wordpress中存在的子页面/子页面的数量?

时间:2010-08-03 01:39:47

标签: php wordpress

基本上我试图在特定父页面的每个子页面中显示类似“查看TotalNumberOfPages的PageNumber”的内容。所以我想弄清楚如何计算存在的子页面/子页面的数量并在子页面上显示它们?

2 个答案:

答案 0 :(得分:2)

以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;

答案 1 :(得分:1)

您可以使用count(get_pages('child_of'=> page_id))来获取子页面的数量。但是为了显示它是例如第2/5页,你必须定义哪个子页面是哪个数字。我建议你在自定义领域这样做。只需将1,2,3,4,5分别放入您呼叫号码或其他内容的每个页面的自定义字段中。