2013-06-25 18 views
1

我試圖解決一些問題,但整個上午都在努力。 我有我的WordPress的帖子已經在他們可以有一個父職位的狀態。 所做:我需要WordPress循環中的章節號

add_action('init', 'add_hierarchy_to_posts'); 
function add_hierarchy_to_posts() { 
    add_post_type_support('post', 'page-attributes'); 
    $obj = get_post_type_object('post'); 
    $obj->hierarchical =true; 
    remove_theme_support('post-formats'); 
} 

我需要我的崗位在數值化的章節因此多數民衆贊成
1.引言
2.主題是偉大的
  2.1爲什麼偉大
  2.2爲什麼受到
    2.2.1更好
    2.2.2更差
      2.2.2.1在最好的情況下
3.結束

現在的問題,怎麼算子章節。 功能是這裏爲止,和它之前的帖子ID產生至少
1.0
2.0
3.0
3.1 3.2

 

global $chapter,$subchapter,$subchapter1,$subchapter2,$depper; 

function is_child_of($postID) { 
    global $post; 

    $ico=$post->post_parent; 
    return $ico; 
} 


function find_out_chapter_number($id){ 

     global $chapter,$subchapter,$subchapter1,$subchapter2,$subchapter3,$depper; 

     if(is_child_of($id)==0){ 
       $chapter++; 
       $subchapter=0; 
     } 
     else if(is_child_of($id)==$depper){ 
       $subchapter++; 
     } 

     $depper=$id; 
     $ico=is_child_of($id); 
     //$id. " - ".$ico." - ". 
     return $chapter.".".$subchapter.".".$subchapter1.".".$subchapter2; 
     }

的$ depper變量存儲。
我需要它更深,我認爲它可能是遞歸的東西,但我不知道。

該函數在wordpress循環中調用

$kapitel = find_out_chapter_number(get_the_ID());
並在the_title()之前回顯;

+0

你能告訴我們這個工作鏈接嗎? – designtocode

+0

這裏下載wordpress插件小部件http://www62.zippyshare.com/v/38624584/file.html – theode

回答

1

請試試這個插件...這將有所幫助。

Page List plugin

,如果你仍然面臨着同樣的問題。請留下您的評論。我會給你另一個解決方案。

+0

但它不顯示數字,對不對? – theode