2017-01-23 68 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), 
)); 

再次:要知道,这是不是正确的解决方案!你应该写一个过滤器为你做这个。每个插件更新都会打破这个功能。