2017-01-23 67 views
1

我使用的分類圖像/ WordPress插件(https://en-gb.wordpress.org/plugins/taxonomy-images/WordPress的分類圖片插件顯示的所有條款

目標:我有一個海報的分類,我想顯示項名稱和術語的形象。我希望能夠顯示,檢索我的分類中的所有術語,無論術語名稱是否爲空。

問題:但是如果兩個數據都沒有輸入,我就不能顯示這個術語。我沒有設法正確使用'hide_empty'。

任何幫助表示讚賞。 感謝

< PHP
/*
模板名稱:GOF海報首頁
*/
// https://en-gb.wordpress.org/plugins/taxonomy-images/
? ?>


< PHP
$分類= '每月類';
$ orderby ='name';
$ order ='ASC';
$ show_count = false;
$ pad_counts = false;
$ hierarchical = true;
$ hide_empty = false;
$ title ='';
$ images ='image_id';

的$ args =陣列(
'分類'= > $分類,
'的OrderBy'= > $的OrderBy,
'順序'= > $順序,
'SHOW_COUNT個'= > $ SHOW_COUNT個,
'pad_counts'= > $ pad_counts,
'分層'= > $分層,
'hide_empty'= > $ hide_empty,
'title_li'= > $ title
);

// $ terms = get_terms('month-category',$ args);
// $ terms = apply_filters('taxonomy-images-get-terms','month-category',$ args);
$ terms = apply_filters('taxonomy-images-get-terms','',$ args);

如果(空($計算)& & is_wp_error($條件)!){
$計數=計數($條件);
$ i = 0;
$ term_list ='< div id =「poster-cat-wrapper」>';
的foreach($條款$項){
$ term_list。=
'< DIV CLASS = 「海報貓」 >'。
'< a href =「/ posters /?gof ='。$ term- > name。''>'。
wp_get_attachment_image($ term- > $ images,'detail')。
'<p>'。 $ term- >名稱。 '</p >'。
'</a >'。
'</div >';
$ i ++;
//'< a href =「/ posters /?gof ='。$ term- > name。''>'。 $ term- >名稱。 '</a >';
if($ count = $ i){
$ term_list。=''; 。
}
否則{
$ term_list = '< /格>';
}
}


}

? >

回答

0

我想不出如何做到這一點,但我發現了一個討厭的黑客。尋找這部分「公共filters.php」在「/插件/分類圖像/」:

$args = wp_parse_args($args, array(
    'cache_images' => true, 
    'having_images' => true, 
    'taxonomy'  => 'category', 
    'term_args'  => array('hide_empty' => false), 
)); 

它改成這樣:

$args = wp_parse_args($args, array(
    'cache_images' => true, 
    'having_images' => true, 
    'taxonomy'  => 'category', 
    'term_args'  => array('hide_empty' => false), 
)); 

再次:要知道,這是不是正確的解決方案!你應該寫一個過濾器爲你做這個。每個插件更新都會打破這個功能。