【发布时间】:2018-03-23 19:32:00
【问题描述】:
我相信我在这里遇到了语法错误,如果有任何帮助解决...
将不胜感激我正在尝试使用 $_GET 函数修改 woocommerce 图像占位符的 img src,以便它通过 php 在 url 中回显变量 [/'thumb/']。
我正在编辑的模板文件是 product-image.php,特别是第 54 行: $html .= sprintf( '
我已经修改为:
if ( has_post_thumbnail() ) {
$html = '<div data-thumb="' . get_the_post_thumbnail_url( $post->ID, 'shop_thumbnail' ) . '" class="woocommerce-product-gallery__image"><a href="' . esc_url( $full_size_image[0] ) . '">';
$html .= get_the_post_thumbnail( $post->ID, 'shop_single', $attributes );
$html .= '</a></div>';
} else {
$html = '<div class="woocommerce-product-gallery__image--placeholder">';
$html .= sprintf( '<img src="http://asharkey.com/<?php echo $_GET[\'thumb\']; ?>" alt="%s" class="wp-post-image" />', esc_url( wc_placeholder_img_src() ), esc_html__( 'Awaiting product image', 'woocommerce' ) );
$html .= '</div>';
}
echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', $html, get_post_thumbnail_id( $post->ID ) );
do_action( 'woocommerce_product_thumbnails' );
?>
【问题讨论】:
-
$html .= sprintf( '<img src="http://asharkey.com/%s" alt="%s" class="wp-post-image" />', $_GET['thumb'].esc_url( wc_placeholder_img_src() ), esc_html__( 'Awaiting product image', 'woocommerce' ) ); -
感谢此代码。除了一件事之外,它几乎是完美的,我用 .esc_url 替换了以下内容: esc_url
标签: php html wordpress woocommerce echo