我对 woocommerce 有疑问。我正在使用 woocommerce_before_main_content
Hook 添加 .jumbotron
页面封面。我能够显示需要出现在背景图片上的页面标题和类别等内容,但显示的图片是破旧的,我不知道为什么,但 wordpress 会显示第一个产品图片缩略图和图片我选择了 woocommerce 的商店页面内的特色是不同的。有解决办法吗?
我正在使用这段代码:
function btheme_woocommerce_before_main_content()
{
if( has_post_thumbnail() ):
?>
<div class="jumbotron jumbotron-fluid shop-page-cover" style="background-image:url('<?php echo the_post_thumbnail_url(); ?>');">
<!-- <div class="parallax" data-parallax-image></div> -->
<div class="container">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12 text-center">
<h1 class=""><?php woocommerce_page_title(); ?></h1>
<?php $categories = get_terms( array('taxonomy' => 'product_cat') ); ?>
<?php foreach( $categories as $category ): ?>
<h4 class="category-name d-inline"><?php echo $category->name; ?></h4>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
<?php endif; ?>
<div class="container-fluid content-wrapper" id="uptheme-woocommece-wrapper">
<?php
}
add_action( 'woocommerce_before_main_content', 'btheme_woocommerce_before_main_content', 10 );
最佳答案
首先你需要通过id获取帖子缩略图
<?php
$shop_page_id = wc_get_page_id('shop');
function btheme_woocommerce_before_main_content()
{
if( has_post_thumbnail($shop_page_id) ):
?>
<div class="jumbotron jumbotron-fluid shop-page-cover" style="background-image:url('<?php echo get_the_post_thumbnail_url($shop_page_id,'full'); ?>');">
<!-- <div class="parallax" data-parallax-image></div> -->
<div class="container">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12 text-center">
<h1 class=""><?php woocommerce_page_title(); ?></h1>
<?php $categories = get_terms( array('taxonomy' => 'product_cat') ); ?>
<?php foreach( $categories as $category ): ?>
<h4 class="category-name d-inline"><?php echo $category->name; ?></h4>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
<?php endif; ?>
<div class="container-fluid content-wrapper" id="uptheme-woocommece-wrapper">
<?php
}
add_action( 'woocommerce_before_main_content', 'btheme_woocommerce_before_main_content', 99 );
关于php - 获取 woocommerce 商店页面发布缩略图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59809375/