您正在尝试连接foreach
语句转换为字符串,这无法完成。。。您需要将所需的输出添加到现有字符串中,而不是连接它
function create_galeri_shortcode( $atts ) {
$atts = shortcode_atts(
array(
),
$atts,
\'galeri\'
);
if ( has_post_format( \'gallery\' ) ) {
$images = get_post_meta( get_the_ID(), \'vdw_gallery_id\', true );
if( $images ) {
$out = \'<div id="lightgallery">\'.
foreach ($images as $imageid) {
$altyazi = get_post_meta( get_the_ID(), \'_wp_attachment_image_alt\', true );
$out .= \'<a href="\'.wp_get_attachment_url($imageid, \'large\').\'" data-sub-html=".caption">\';
$out .= \'<img src="\'.wp_get_attachment_url($imageid, \'thumbnail\').\'" alt="\'.$altyazi.\'">\';
$out .= \'<div class="caption">\';
$out .= \'<h4>\'.$altyazi.\'</h4>\';
$out .= \'<p>\'.wp_get_attachment_caption( $imageid ).\'</p>\';
$out .= \'</div>\';
$out .= \'</a>\';
}
$out .= \'</div>\';
}
}
return $out;
}
add_shortcode( \'galeri_mm\', \'create_galeri_shortcode\' );