如何获得woocommerce商店页面的特色图片网址?

时间:2018-09-06 15:27:26

标签: php wordpress woocommerce

这是我尝试获取要设置为BG的特色图片网址的代码。对于page.php来说工作正常。但是在Woocommerce Shop(后类型存档产品)页面中,它显示的是产品特色图片之一,而不是页面特色图片。

任何解决方案?

<?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

1 个答案:

答案 0 :(得分: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

相关问题