Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果变量为link,则为echo link_Php_Wordpress_Function - Fatal编程技术网

Php 如果变量为link,则为echo link

Php 如果变量为link,则为echo link,php,wordpress,function,Php,Wordpress,Function,我在获取要回显的函数时遇到问题,其中$lightbox\u link1=获取自定义字段('lightbox\u link1')。我对PHP相当陌生 以下是定义函数: // Check for a lightbox link, if it exists, use that as the value. // If it doesn't, use the featured image URL from above. if(get_custom_field('lightbox_link1')) {

我在获取要回显的函数时遇到问题,其中
$lightbox\u link1
=
获取自定义字段('lightbox\u link1')
。我对PHP相当陌生

以下是定义函数:

// Check for a lightbox link, if it exists, use that as the value. 
// If it doesn't, use the featured image URL from above.
if(get_custom_field('lightbox_link1')) {                            
    $lightbox_link1 = get_custom_field('lightbox_link1');
} else {                            
    $lightbox_link1 = $image_full[0];
}
回音功能:

<?php if ($lightbox_link1 = get_custom_field('lightbox_link1')) {
     echo '<a href="<?php echo $lightbox_link1; ?>" data-rel="prettyPhoto[<?php echo $post_slug; ?>]"></a>';
} ?>

相反,在
echo
语句中使用双引号将允许解析其中的php变量,因此您可以这样做

echo "<a href='{$lightbox_link1}' data-rel='prettyPhoto[{$post_slug}]'></a>";
echo”“;
得到

<?php if ($lightbox_link1 == get_custom_field('lightbox_link1')) {
     echo "<a href='{$lightbox_link1}' data-rel='prettyPhoto[{$post_slug}]'></a>";
} ?>


您为两行编写了相同的内容<代码>很抱歉,为了清晰起见,我重新编辑了,并做出了复制粘贴错误的解释!非常感谢。
 <?php if ($lightbox_link1 = get_custom_field('lightbox_link1')) {
    echo '<a href="<?php
echo "<a href='{$lightbox_link1}' data-rel='prettyPhoto[{$post_slug}]'></a>";
<?php if ($lightbox_link1 == get_custom_field('lightbox_link1')) {
     echo "<a href='{$lightbox_link1}' data-rel='prettyPhoto[{$post_slug}]'></a>";
} ?>