如何将 wooCommerce 类别的图像设置为类别标题的背景


How can I set the Image of woocommerce category as the background of the category title?

我想将woocommerce类别图像设置为标题背景。

这是存档产品中的标题行.php

<h1 class="page-title"><?php woocommerce_page_title(); ?></h1>

我写了

                <h1 style="background: url(<?php if ( is_product_category() ){
    global $wp_query;
    $cat = $wp_query->get_queried_object();
    $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true ); 
    $image = wp_get_attachment_url( $thumbnail_id ); 
    echo "<img src='{$image}' alt='' width='762' height='365' />";
}   
?>);" class="page-title"><?php woocommerce_page_title(); ?></h1>

我可以在浏览器编辑器中看到图像!但是有些不对劲。我该如何解决这个问题?

<?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>
            <h1 style="background: url(<?php if ( is_product_category() ){
    global $wp_query;
    $cat = $wp_query->get_queried_object();
    $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true ); 
    $image = wp_get_attachment_url( $thumbnail_id ); 
    echo "'{$image}'";
}   
?>);" class="page-title"><?php woocommerce_page_title(); ?></h1>

我按照如何显示Woocommerce类别图像?并设置echo "'{$image}'";
而不是echo "<img src='{$image}' alt='' width='762' height='365' />";