简体   繁体   English

如果自定义字段= true,则将图像插入PHP代码

[英]Inserting an image into PHP code if custom field = true

I have the following code which is pulling in a custom field named phone. 我有以下代码正在提取一个名为phone的自定义字段。

<?php echo get_post_meta( get_the_ID(), 'ecpt_phone', true ); ?>

I additionally however want to add a little icon to the left of it. 但是,我还想在其左侧添加一个小图标。 So I realise I have to include the src link somewhere, have tried the below, but am having no joy. 因此,我意识到我必须将src链接包括在某处,并尝试了以下内容,但我并不高兴。 Sorry a bit new... 对不起,有点新...

<?php
$value = get_post_meta( get_the_ID(), 'ecpt_phone', true );
if( $value == 'True' ) { echo '<img src="/wp-content/uploads/2013/02/image.png">'; echo get_post_meta( get_the_ID(), 'ecpt_phone', true ); ?>

Thanks so much in advance. 非常感谢。

尝试在字符串定义中反转'和'。这导致

"<img src='/wp-content/uploads/2013/02/image.png'>";

src删除第一个/ ,然后尝试。

echo '<img src="wp-content/uploads/2013/02/image.png">';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM