【问题标题】:WooCommerce Category and ACFWooCommerce 类别和 ACF
【发布时间】:2015-06-15 07:49:42
【问题描述】:

我正在使用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 类别屏幕截图: http://www.directupload.net/file/d/3952/kzb8dcjk_png.htm

【问题讨论】:

    标签: wordpress woocommerce advanced-custom-fields


    【解决方案1】:

    您尚未为get_field() 函数设置$postId 参数,因此它默认为当前帖子对象(这可能是该类别中的第一个帖子)。

    有关如何从其他地方获取字段的说明,请参阅documentation 中的从其他地方获取值部分。

    所以你会想写这样的东西:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-26
      • 2016-09-20
      • 2019-09-13
      • 1970-01-01
      • 2016-07-02
      • 2017-06-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多