首页 文章

WooCommerce类别和ACF

提问于
浏览
1

我正在使用Advanced Custom Fields(ACF)插件 . 在WooCommerce产品类别中,我想要一个seo的内容区域 . ACF会帮助我,但不起作用,因为网站的前端没有显示任何内容 .

content-product.php 有额外的字段:

<li <?php post_class(); ?> style="max-width:<?php echo $column_width; ?>px">
    <div class="mk-product-holder">
    <?php do_action( 'woocommerce_before_shop_loop_item' ); ?>

        <div class="mk-love-holder">
        <?php if( function_exists('mk_love_this') ) mk_love_this();      ?>
        </div>

        <h3><a href="<?php echo get_permalink();?>"><?php the_title(); ?></a>

        // Here is the extrafield SEO-text, the field is registered in fields with name "extratext"
        <?php echo get_field('extratext'); ?>       

        </h3>
    </div>
</li>

WooCommerce Category Screenshot: http://www.directupload.net/file/d/3952/kzb8dcjk_png.htm

1 回答

  • 4

    你没有't set the $postId parameter for the get_field() function so it'默认为当前的帖子对象(这可能是该类别中的第一个帖子) . 有关如何从其他位置获取字段的说明,请参阅文档中的 Get a value from other places 部分:http://www.advancedcustomfields.com/resources/get_field/ .

    所以你要写这样的东西:

    <?php
    $queriedObject=get_queried_object();
    echo get_field('extratext','product_cat_'.$queriedObject->term_id);
    ?>
    

相关问题