dtl85148 2015-08-10 12:29
浏览 23

自定义帖子标记图像不显示

Using ACF i've added a custom image field to a particular set of custom post tags. The problem I have is that I cannot get the images to display. Yes, I have added an image to the tag and updated.

   $term_id = 26;
    $taxonomy_name = 'tags';
    $termchildren = get_term_children( $term_id, $taxonomy_name );

    foreach ( $termchildren as $child ) {

        $term = get_term_by( 'id', $child, $taxonomy_name );
        $tag_image = get_field('tag_image');
        echo '<a href="?categories=' . $term->slug . '">'. $term->name . '</a>';
        echo $tag_image; //this bit doesn't work :(


    }

Fixed, the new code is:

    <?php

        $term_id = 26;
        $taxonomy_name = 'tags';
        $termchildren = get_term_children( $term_id, $taxonomy_name );

        foreach ( $termchildren as $child ) {

            $term = get_term_by( 'id', $child, $taxonomy_name );
            $tag_image = get_field('tag_image', $term);
            echo '<a href="?categories=' . $term->slug . '" class="one-third column">'. $term->name;

        ?>

            <? if( !empty($tag_image) ): ?>

                <img src="<? echo the_field('tag_image', $term); ?>" />

            <?php endif; 

            echo '</a>';


         }

    ?> 

Resource for the fix was here http://www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/

  • 写回答

1条回答 默认 最新

  • dtnnpt11795 2015-08-10 14:26
    关注
     <?php
    
        $term_id = 26;
        $taxonomy_name = 'tags';
        $termchildren = get_term_children( $term_id, $taxonomy_name );
    
        foreach ( $termchildren as $child ) {
    
            $term = get_term_by( 'id', $child, $taxonomy_name );
            $tag_image = get_field('tag_image', $term);
            echo '<a href="?categories=' . $term->slug . '" class="one-third column">'. $term->name;
    
        ?>
    
            <? if( !empty($tag_image) ): ?>
    
                <img src="<? echo the_field('tag_image', $term); ?>" />
    
            <?php endif; 
    
            echo '</a>';
    
    
         }
    
    ?> 
    

    http://www.advancedcustomfields.com/resources/get-values-from-a-taxonomy-term/

    评论

报告相同问题?

悬赏问题

  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题