據(jù)說(shuō) wp_list_categories() 函數(shù)返回一個(gè)字符串。但是,它不會(huì)返回任何內(nèi)容,而是在另一個(gè)位置激活類(lèi)別列表的輸出。頁(yè)面內(nèi)容生成如下function build_index_posts(...){ $html = ''; $html.= '<div class="one">'; $html.= '<h1>'.$header_arr['title'].'</h1>'; $html.= '</div>'; return $html;} 我試圖輸出一個(gè)包含子類(lèi)別列表的塊,但它沒(méi)有插入到指定位置,而是插入到頁(yè)面的最開(kāi)頭。 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; } 如何在適當(dāng)?shù)膲K中插入類(lèi)別列表?
1 回答

萬(wàn)千封印
TA貢獻(xiàn)1891條經(jīng)驗(yàn) 獲得超3個(gè)贊
有兩種使用方法wp_list_categories()- 您使用它的方式將立即輸出代碼中調(diào)用它的列表 - 這就是您在頁(yè)面頂部看到它的原因。
如果您想獲取類(lèi)別列表作為變量,則需要傳遞包含echo值為false(默認(rèn)為 true)的參數(shù):
$li_args = array(
? ? ?'echo' => false,
? ? ? /* the rest of your args */
);
// now you can save the list in a variable.
$cat_list = wp_list_categories($li_args);
- 1 回答
- 0 關(guān)注
- 133 瀏覽
添加回答
舉報(bào)
0/150
提交
取消