据说 wp_list_categories() 函数返回一个字符串。但是,它不会返回任何内容,而是在另一个位置激活类别列表的输出。
页面内容生成如下
function build_index_posts(...){
$html = '';
$html.= '<div class="one">';
$html.= '<h1>'.$header_arr['title'].'</h1>';
$html.= '</div>';
return $html;
}
我试图输出一个包含子类别列表的块,但它没有插入到指定位置,而是插入到页面的最开头。
function build_index_posts(...){
$html = '';
$html.= '<div class="one">';
$html.= '<h1>'.$header_arr['title'].'</h1>';
$html.= '</div>';
$category = get_queried_object();
$category_id = $category->term_id;
$li_args = array(
'child_of' => $category_id,
'depth' => 1,
'style' => 'none',
'hide_empty' => 0,
'orderby' => 'name',
'show_count' => 0,
'pad_counts' => 0,
'hierarchical' => 1,
'title_li' => ''
);
$cat_list = wp_list_categories($li_args);
$cat_list = str_replace('<br>', '', $cat_list);
$html.= '<div style="display: none">';
$html.= $cat_list; // NULL ??
$html.= '</div>';
return $html;
}
如何在适当的块中插入类别列表?
万千封印