我试图解决一些问题,但整个上午都在挣扎。我的 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. 结束
现在的问题是,如何计算子章节。该函数到此为止,它至少产生
1.0
2.0
3.0
3.1
3.2
全局 $chapter,$subchapter,$subchapter1,$subchapter2,$depper;
功能 is_child_of($postID) {
全球 $post;
$ico=$post->post_parent;
返回$ico;
}
函数 find_out_chapter_number($id){
全局 $chapter,$subchapter,$subchapter1,$subchapter2,$subchapter3,$depper;
if(is_child_of($id)==0){
$章节++;
$子章节=0;
}
否则 if(is_child_of($id)==$depper){
$子章节++;
}
$depper=$id;
$ico=is_child_of($id);
//$id。“ - “.$ico。” - “。
返回 $chapter.".".$subchapter.".".$subchapter1.".".$subchapter2;
}
$depper 变量存储之前的帖子 ID。
我需要它更深,我认为它可能是递归的,但我不知道。
该函数是从 wordpress 循环中调用的
$kapitel = find_out_chapter_number(get_the_ID());并在 the_title() 之前回显;