doushi1974 2015-12-10 16:03
浏览 53
已采纳

使用ACF从分类术语中获取图像

I am using the below code to try and retrieve an image field called 'image' from a taxonomy term using the Advanced Custom Fields plugin. This code is based on the documentation on the ACF website here.

It should be noted this code is being used within the taxonomy.php template, and I am unable to specify particular taxonomy and/or terms as I need the code to detect the current taxonomy and term, based on the page the user and clicked through to.

Any help much appreciated!

<?php get_header(); ?>
<?php get_sidebar(); ?>

<section id="hero-image">
    <div class="gradient-overlay">
        <?php 
        // vars
        $queried_object = get_queried_object(); 
        $taxonomy = $queried_object->taxonomy;
        $term_id = $queried_object->term_id;  

        // load thumbnail for this taxonomy term (term object)
        $image = get_field('image', $queried_object);

        // load thumbnail for this taxonomy term (term string)
        $image = get_field('image', $taxonomy . '_' . $term_id);
        ?>
    </div>
    <div class="grid">
        <header class="unit full-width">
            <a href="<?php echo home_url(); ?>/" title="Kurdistan Memory Programme" class="logo"><?php bloginfo( 'name' ); ?></a>
        </header>
        <footer class="unit one-half">
            <h1><?php single_cat_title(); ?></h1>
            <h4 class="scroll-down">Scroll down to continue</h4>
        </footer>
    </div>
</section>

<?php get_footer(); ?>

enter image description here

  • 写回答

2条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 结构体数组文件读取问题
      • ¥15 写c++代码,第7题说一下使用的计算方法
      • ¥15 postman接口自动化测试报告实践总结
      • ¥15 有关c++的问题,利用相关知识
      • ¥15 求香农编码和解码的matlab代码
      • ¥20 ROS中的TEB局部规划问题
      • ¥20 关于#matlab#的问题:要求测出上面图片中所有同心圆的半径
      • ¥20 epanet软件运行问题
      • ¥15 Python 文件读取
      • ¥60 dpabi进行Alff计算时脑池有干扰信号