Kie*_*erd 2 wordpress woocommerce 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>
Run Code Online (Sandbox Code Playgroud)
WooCommerce类别屏幕截图: http ://www.directupload.net/file/d/3952/kzb8dcjk_png.htm
小智 5
您尚未设置该函数的$postId
参数get_field()
,因此默认将其设置为当前的post对象(可能是类别中的第一篇文章)。
请参阅文档中的“ 从其他位置获取值”部分,以获取有关如何从其他位置获取字段的说明。
因此,您需要编写如下内容:
<?php
$queriedObject=get_queried_object();
echo get_field('extratext','product_cat_'.$queriedObject->term_id);
?>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3053 次 |
最近记录: |