【问题标题】:Concatenating PHP in img src with echo $_GET function在 img src 中使用 echo $_GET 函数连接 PHP
【发布时间】:2018-03-23 19:32:00
【问题描述】:

我相信我在这里遇到了语法错误,如果有任何帮助解决...

将不胜感激

我正在尝试使用 $_GET 函数修改 woocommerce 图像占位符的 img src,以便它通过 php 在 url 中回显变量 [/'thumb/']。

示例网址是: http://asharkey.com/product/limited-edition-print/?title=20090629-DSC_2131.jpg&thumb=galleries/portfolio/images/20090629-DSC_2131.jpg&image_title=Kenyan%20Dance

我正在编辑的模板文件是 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( '&lt;img src="http://asharkey.com/%s" alt="%s" class="wp-post-image" /&gt;', $_GET['thumb'].esc_url( wc_placeholder_img_src() ), esc_html__( 'Awaiting product image', 'woocommerce' ) );
  • 感谢此代码。除了一件事之外,它几乎是完美的,我用 .esc_url 替换了以下内容: esc_url

标签: php html wordpress woocommerce echo


【解决方案1】:

ccKep 的评论几乎是正确的,接受一个标点符号...下面是正确的代码:

$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' ) );

谢谢!

【讨论】:

    猜你喜欢
    • 2014-05-25
    • 1970-01-01
    • 2020-07-13
    • 1970-01-01
    • 2016-02-11
    • 1970-01-01
    • 1970-01-01
    • 2014-12-08
    • 1970-01-01
    相关资源
    最近更新 更多