在Wordpress中使用taxonomy Meta插件获取分类法图像有问题



我正在使用Taxonomy Meta插件,并遵循所有指示,但感觉我正在做的事情有问题。我只是想把分配给每个类别的图像作为自定义分类法,并将其显示在页面模板上。

插件的github repo可以在这里找到: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在那里,看看它是否工作,它确实,但如果我尝试使用$category->term_id它不工作,我有点迷失了从这里..

更新:我现在能够拉分配给每个类别的图像并打印名称,但我得到这个错误"警告:为foreach()提供的无效参数在/home//themes//my-template.php第39行"

我的代码

$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) {

明白了

$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'];
if (empty($images)) {
    echo '<a href="/term-base/' . $term->slug . '" title="' . sprintf(__('View all post filed under %s', 'my_localization_domain'), $term->name) . '"><p style="text-align:center;">' . $term->name . '</p></a>';
} else {
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.'" /><p style="text-align:center;">' . $term->name . '</p></a>';
}}
}
}

最新更新