如何修改WordPress自帶標籤雲小工具的顯示參數

有些WordPress主題使用的是WordPress自帶的標籤雲小工具,默認的顯示個數、字體大小、排序等也許不能滿足你的需求,好在WordPress提供了  widget_tag_cloud_args 這個 filter可以修改默認的參數。
在你當前主題的 functions.php 文件添加下面的代碼即可:
  1. //custom widget tag cloud

  2. add_filter( 'widget_tag_cloud_args', 'theme_tag_cloud_args' );

  3. function theme_tag_cloud_args( $args ){

  4. $newargs = array(

  5. 'smallest'    => 8,  //最小字號

  6. 'largest'     => 22, //最大字號

  7. 'unit'        => 'pt',   //字號單位,可以是pt、px、em或%

  8. 'number'      => 45,     //顯示個數

  9. 'format'      => 'flat',//列表格式,可以是flat、list或array

  10. 'separator'   => "\n",   //分隔每一項的分隔符

  11. 'orderby'     => 'name',//排序字段,可以是name或count

  12. 'order'       => 'ASC', //升序或降序,ASC或DESC

  13. 'exclude'     => null,   //結果中排除某些標籤

  14. 'include'     => null,  //結果中只包含這些標籤

  15. 'link'        => 'view' //taxonomy鏈接,view或edit

  16. 'taxonomy'    => 'post_tag', //調用哪些分類法作爲標籤雲

  17. );

  18. $return = array_merge( $args, $newargs);

  19. return $return;

  20. }


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章