我正在使用Taxonomy Meta插件,并且已经遵循所有的instrauctions,但觉得我正在做的事情有些问题。我只是想拉图像分配给每个类别是一个自定义分类和页面模板显示它..在Wordpress中使用Taxonomy Meta插件获取分类图像时遇到问题
插件的GitHub库可以在这里找到:https://github.com/rilwis/taxonomy-meta
请大家帮忙,我让一切都显示出来,但图像,当我看到源图像路径不存在只是一个空的img标签。
我能得到的图像使用该打印:
$meta = get_option('additional');
if (empty($meta)) $meta = array();
if (!is_array($meta)) $meta = (array) $meta;
$meta = isset($meta['5']) ? $meta['5'] : array();
$images = $meta['community-image'];
echo '<ul>';
foreach ($images as $categories) {
// get image's source based on size, can be 'thumbnail', 'medium', 'large', 'full' or registed post thumbnails sizes
$src = wp_get_attachment_image_src($categories, 'thumbnail');
$src = $src[0];
$args=array(
'orderby' => 'name',
'order' => 'ASC',
'taxonomy' => 'properties_community'
);
$categories=get_categories($args);
// show image
foreach($categories as $category) {
echo '<li><a href="' . home_url() . '/?property_communities='. $category->slug .'" title="' . sprintf(__("View all posts in %s"), $category->name) . '" ' . '><img src="'.$src.'"/>' . $category->name.'</a> </li> ';
}
}
echo '</ul>';
,但我无法弄清楚如何在图像匹配所显示的类别做吧..我只是把数字5在那里看如果它的工作,它不会,但如果我尝试使用$分类 - > term_id它不工作,我有点从这里失去了..
UPDATE: 我现在能拉分配给每个类别的图像并打印名称,但我得到这个错误“警告:为foreach提供的无效参数()在第39" 行上/home/../themes/../my-template.php
这里是我的代码
$args = array('taxonomy' => 'properties_community');
$terms = get_terms('properties_community', $args);
$count = count($terms); $i=0;
if ($count > 0) {
$cape_list = '<p class="my_term-archive">';
foreach ($terms as $term) {
$meta = get_option('additional');
if (empty($meta)) $meta = array();
if (!is_array($meta)) $meta = (array) $meta;
$meta = isset($meta[$term->term_id]) ? $meta[$term->term_id] : array();
$images = $meta['community-image'];
foreach ($images as $att) {
// get image's source based on size, can be 'thumbnail', 'medium', 'large', 'full' or registed post thumbnails sizes
$src = wp_get_attachment_image_src($att, 'medium');
$src = $src[0];
// show image
echo '<a href="/term-base/' . $term->slug . '" title="' . sprintf(__('View all post filed under %s', 'my_localization_domain'), $term->name) . '"><img src="'.$src.'" />' . $term->name . '</a>';
}}
}
任何人都明白我为什么会收到此错误?我看不出什么毛病的foreach:/
线39将是这样:foreach ($images as $att) {