在<img scr="

时间:2016-10-21 08:43:38

标签: php woocommerce

="" 中使用变量我有以下代码:

create audit

我已经尝试了许多谷歌搜索的各种解决方案,但没有一个对我有用,因为它们都输出了html标签。我的输出如下:

Output from code

这可能实现吗?

谢谢!

3 个答案:

答案 0 :(得分:0)

正如文档https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/中所述,它返回标记,而不是网址。 要获取网址,请执行

$image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail' );

转到doc https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/了解更多信息;)

答案 1 :(得分:0)

我认为你的$catimg没有返回任何内容或空字符串
我已经尝试过这个代码在php中使用静态图像,它的工作正常,所以你的字符串插值是正确的。请检查您的$catimg变量

<?php
//This one gets the image from the first product in the product category category:

$catimg = 'https://pbs.twimg.com/profile_images/718314968102367232/ypY1GPCQ_400x400.jpg';
$variable1 = "Rajesh";
$variable = "Text";
//This code contains custom text that also reads info from various variables, including the `$catimg` variable:

$cat_art1 =  '<h1>'.$variable1.' This is some text that will be outputted to my site.</h1>
Here i want to screen the image <img src="' . $catimg . '" alt="alt">
Some more text and another '.$variable.' to end the line';
echo $cat_art1;
?>

答案 2 :(得分:0)

Reference: To Get image url

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_VOLUME_DOWN: {
            // Do something when volume down button is clicked

            return true;
        }
        case KeyEvent.KEYCODE_VOLUME_UP: {
            // Do something when volume up button is clicked

            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}
相关问题