我正在使用两个插件WPCustom类别图像,以便能够在每个类别中插入图像,W4帖子列表用于在屏幕上列出类别。
在这一刻,给我永远是类别的最后一幅图像。我假装每个类别的图像对应于每个 ID。
该插件有一个短代码 [term_id],它显示相应的类别 ID,但我不能从另一个短代码中使用一个短代码。
示例 - [wp_custom_image_category onlysrc="false" size="full" term_id="[term_id"]]
有什么解决办法吗?
foreach( get_categories(['hide_empty' => false]) as $category) {
$image = do_shortcode('[wp_custom_image_category onlysrc="false" size="full" term_id="'.$category->term_id.'" ]');
echo $image.'<br/>';
// $id = 4;
$options['template'] =
'[terms]
<div class="col-sm-3 news-cat-links" id="[term_id]">
<a href="[term_link]">[term_name]</a><img src="'.$image.'" /></a>
</div>[/terms]';
}
转到相应的插件文件,找到[term_id]
短代码的功能。
下面的代码返回名为"eventcategory"的自定义texanomy数组。 将$post定义为全局变量。
$terms = get_the_terms( $post->ID, 'eventcategory' );
if ( $terms && ! is_wp_error( $terms ) ) :
$draught_links = array();
foreach ( $terms as $term ) {
$draught_links[] = $term->name;
}
print_r($draught_links);