php if 语句内的 href 内的变量

php variable inside href inside if statement

我正在尝试使缩略图图像可点击,以便在点击时显示完整尺寸的图像,但我一直收到 PHP 错误,我不确定为什么。这是一个 Wordpress 网站。我怀疑它与 URL 中的变量有关,但我需要一些指导。我已经搜索了将近 8 个小时的堆栈...这是我的代码:

if ( has_post_thumbnail() ) {
    echo '<a href="'get_the_post_thumbnail_url($post_id, 'full');'">';
    the_post_thumbnail('cb-thumb-600-crop');
    echo '</a>';
        } else {

我认为你的代码有问题:

echo '<a href="'get_the_post_thumbnail_url($post_id, 'full');'">';

应该是:

echo '<a href="' . get_the_post_thumbnail_url($post_id, 'full') . '">';

试试这个:

if ( has_post_thumbnail() ) {
$anything=get_the_post_thumbnail_url($post_id, 'full');
$anythings=the_post_thumbnail('cb-thumb-600-crop');
echo '<a href="'.$anything.'">'.$anythings.'</a>';
    } else {

问题出在这一行:

echo  '<a href="'get_the_post_thumbnail_url($post_id, 'full');'">';

您忘记了 "get_" 和 ");"

附近的单引号之间的点

它应该看起来像这样:

echo '<a href="' . get_the_post_thumbnail_url($post_id, 'full') . '">';

祝你好运,继续编码! :)