如何获得woocommerce商店页面的精选图片网址?

问题描述 投票:0回答:1

这是我试图将特色图片网址设置为BG的代码。它对page.php工作正常。但是在Woocommerce Shop(post-type-archive-product)页面中,它显示的是产品特色图像而不是页面特色图像。

任何解决方案

<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );?>

    <header style="background-image: url('<?php echo $thumb['0']; ?>')" class="inner-page-header">
        <div class="wrap">
            <div class="page_header">
                    <?php the_title(); ?>
            </div>
        </div>
    </header>

enter image description here

php wordpress woocommerce
1个回答
1
投票

您可以使用wc_get_page_id()获取页面ID并使用它来获取图像源。这应该工作。

<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id( wc_get_page_id( 'shop' ) ), 'full' );?>

    <header style="background-image: url('<?php echo $thumb['0']; ?>')" class="inner-page-header">
        <div class="wrap">
            <div class="page_header">
                <?php the_title(); ?>
            </div>
        </div>
    </header>

这是the documentation

© www.soinside.com 2019 - 2024. All rights reserved.