亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么wp_list_categories()會自動插入到頁面頂部?

為什么wp_list_categories()會自動插入到頁面頂部?

PHP
撒科打諢 2023-09-15 09:47:43
據說 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;    } 如何在適當的塊中插入類別列表?
查看完整描述

1 回答

?
萬千封印

TA貢獻1891條經驗 獲得超3個贊

有兩種使用方法wp_list_categories()- 您使用它的方式將立即輸出代碼中調用它的列表 - 這就是您在頁面頂部看到它的原因。


如果您想獲取類別列表作為變量,則需要傳遞包含echo值為false(默認為 true)的參數:


$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);

查看完整回答
反對 回復 2023-09-15
  • 1 回答
  • 0 關注
  • 119 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號