我遇到问题需要回复,其中$lightbox_link1
= get_custom_field('lightbox_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>';
} ?>
答案 0 :(得分:3)
<?php if ($lightbox_link1 = get_custom_field('lightbox_link1')) {
应该是
<?php if ($lightbox_link1 == get_custom_field('lightbox_link1')) {
=
用于作业
==
用于比较
===
用于类型安全比较
您也无法在另一个<?php ... ?>
<?php ... ?>
获得类似<?php ... <?php ... ?> ... ?>
看看你在这里做了些什么:
<?php if ($lightbox_link1 = get_custom_field('lightbox_link1')) {
echo '<a href="<?php
相反,在echo
语句中使用双引号将允许解析内部的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>";
} ?>