[英]$output = to return some HTML and PHP
I am using Advanced custom fields to display team bios using a shortcode, the client came back to me and wants to have a custom image size that is then masked via CSS. 我正在使用高级自定义字段来使用简码显示团队简介,客户端又回到了我身边,并希望有一个自定义图像大小,然后通过CSS对其进行掩盖。
It was working fine until I tried to add the custom image. 在尝试添加自定义图像之前,它一直运行良好。 using wp_get attachment_src, I am sure I am making an obvious PHP erro, can you help me trouble shoot,
使用wp_get attachment_src,我确定我正在制作明显的PHP错误,您能帮我解决问题,
the code is: 代码是:
function team_profiles_func($atts) {
global $post;
extract(shortcode_atts(array(
'id' => $post->ID
), $atts));
if (get_field('team_profiles')) {
while (has_sub_field('team_profiles')) {
$attachment_id = get_sub_field('employee_photo');
$size = "team";
$image = wp_get_attachment_image_src( $attachment_id, $size );
$output .= '<div class="crew-wrap media">';
$output .= ' <a class="crew-img" href="#">';
$output .= ' <img src="'.echo $image[0].'" class="media-object" alt="">';
$output .= ' </a>';
$output .= ' <div class="media-body">';
$output .= ' <h2 class="media-heading">'.get_sub_field( 'employee_name').'</h2>';
$output .= ' <h4 class="media-heading">'.get_sub_field( 'employee_title').'</h4>';
$output .= ' <p>'.get_sub_field( 'employee_bio').'</p></div>';
$output .= '</div>';
}
}
return $output;
}
echo
is a language construct and does NOT have a return value: echo
是一个语言结构,并没有返回值:
$output .= ' <img src="'.echo $image[0].'" class="etc...
^^^^---incorrect
That echo
will directly dump the value in $image[0]
as output, and you end up generating 该
echo
将直接将$image[0]
的值转储为输出,最终生成
<img src="" class=" etc...
You should have 你应该有
$output .= ' <img src="'. $image[0] .'" class=" etc..
Note the lack of echo. 注意缺少回声。
Your $size
variable can either be a string keyword (thumbnail, medium, large or full) or a 2-item array representing width and height in pixels, eg array(32,32). 您的
$size
变量可以是字符串关键字(缩略图,中,大或完整),也可以是2项数组,以像素为单位表示宽度和高度,例如array(32,32)。 What do you mean by "team"
? "team"
是什么意思?
You can't output PHP from a PHP script, and have it executed. 您无法从PHP脚本输出PHP并执行它。 PHP is executed on the webserver.
PHP在网络服务器上执行。 So the client does not know what to do with it.
因此客户不知道该怎么办。
Instead try this: 而是尝试以下方法:
$output .= ' <img src="' . $image[0] . '" class="media-object" alt="">';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.