我在我的Wordpress主题中有自定义PHP作用域,像这样:
foreach ($myprojects as $post){
setup_postdata( $post );
$output .= '<div class="col-xs-6 col-sm-3">';
$output .= '<div class="portfolio-item">';
if (has_post_thumbnail($post->ID)) {
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'medium');
$large_image = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
$content = get_post_field('post_content', $post_id);
$output .= '<img class="img-responsive" src="'.$thumb[0].'" title="" alt="">';
}else{
$output .= '<img class="img-responsive" src="images/work_1.jpg" title="" alt="">';
}
$post_id = get_the_title($post->ID);
$post_name = CFS()->get('project_name', '');
$output .= '<a class="overlay" rel="shadowbox" href="'.$large_image[0].'">';
$output .= '<p class="btn-preview">'.$post_id.'</p>';
$output .= '</a>';
$output .= '</div>';
$output .= '</div>';
$count++;
$index++;
}
是的,它工作良好。当我点击a
标签时,通过pretypto打开$large_image
。但这是单张图片的代码。我想缩略图保持不变,但当点击链接,通过pretypto打开多个图像。因此,在post body中导入了2张图片,并希望显示这些图片。
简而言之,这段代码:
$large_image = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
必须是这样的:
$large_image = wp_get_attachment_image_src( $body($post->ID), 'full');
但是我知道,这不是正确的代码。其伪。
我怎样才能解决我的问题?谢谢。
将您的灯箱解决方案更改为fancyBox,使用data-fancybox-group
和一点Wordpress/PHP知识…就是这样!
foreach ($myprojects as $post){
setup_postdata( $post );
$output .= '<div class="col-xs-6 col-sm-3">';
$output .= '<div class="portfolio-item">';
if (has_post_thumbnail($post->ID)) {
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'medium');
$large_image = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
$content = get_post_field('post_content', $post_id);
$output .= '<img class="img-responsive" src="'.$thumb[0].'" title="" alt="">';
}else{
$output .= '<img class="img-responsive" src="images/work_1.jpg" title="" alt="">';
}
$post_id = get_the_title($post->ID);
$post_name = CFS()->get('project_name', '');
$output .= '<a class="overlay test fancybox" data-fancybox-group="'.$post->ID.'" href="'.$large_image[0].'">';
$output .= '<p class="btn-preview">'.$post_id.'</p>';
$output .= '</a>';
$output .= '</div>';
$output .= '</div>';
$attached_images = get_attached_media('image', $post->ID);
foreach($attached_images as $image){
$large_attached_image = wp_get_attachment_image_src($image->ID,'full');
if($large_image[0] != $large_attached_image[0]){
$output .= '<a class="overlay test fancybox" data-fancybox-group="'.$post->ID.'" style="display:none" href="'.$large_attached_image[0].'"></a>';
}
}
$count++;
$index++;
}