目前,如果我使用像这样的旧库短代码,下面的代码运行良好[gallery]
. 但是,在Wordpress 3.5更新gallery后,默认情况下,短代码现在包括图像ID,如下所示[gallery ids="766,765,764,763,762,761"]
.
带有ID的新短代码阻止画廊显示。我应该如何使其兼容?如果我使用[gallery ids="766,765,764,763,762,761"]
<div class="gallery-content">
<?php
if( has_shortcode( $post->post_content, \'gallery\' ) ) :
if ( $images = get_children(array(\'post_parent\' => get_the_ID(),\'post_type\' => \'attachment\',\'post_mime_type\' => \'image\', \'orderby\' => \'menu_order_ID\'))) :
$image_list = \'<ul class="galleryslider">\';
foreach( $images as $image ) :
$attachmenturl=wp_get_attachment_url($image->ID);
$attachmentimage=wp_get_attachment_image($image->ID, \'full\' );
$img_title = $image->post_title;
$img_desc = $image->post_excerpt;
$image_list .= \'<li><a href="\'.$attachmenturl.\'" \'. $lightbox .\' data-title="\'.$img_desc.\'" title="\'.$img_title.\'"><div class="gallery-image-title">\'.$img_title.\'</div>\'.$attachmentimage.\'</a><div class="gallery-image-desc">\'.$img_desc.\'</div></li>\';
endforeach;
$image_list .= \'</ul>\';
echo $image_list;
endif;
endif;
?>
</div><!-- .gallery-content -->
最合适的回答,由SO网友:Mohammed 整理而成
取决于您的代码,如果您将其用作gallery快捷码,我认为这将起作用:
<div class="gallery-content">
<?php
if( has_shortcode( $post->post_content, \'gallery\' ) ) :
if ($ids != \'\') {
$images = explode(\',\', $ids);
} else {
$images = get_children(array(\'post_parent\' => get_the_ID(),\'post_type\' => \'attachment\',\'post_mime_type\' => \'image\', \'orderby\' => \'menu_order_ID\'))
}
if ($images) :
$image_list = \'<ul class="galleryslider">\';
foreach( $images as $image ) :
if ($ids != \'\') {
$image = get_post($image);
}
$attachmenturl=wp_get_attachment_url($image->ID);
$attachmentimage=wp_get_attachment_image($image->ID, \'full\' );
$img_title = $image->post_title;
$img_desc = $image->post_excerpt;
$image_list .= \'<li><a href="\'.$attachmenturl.\'" \'. $lightbox .\' data-title="\'.$img_desc.\'" title="\'.$img_title.\'"><div class="gallery-image-title">\'.$img_title.\'</div>\'.$attachmentimage.\'</a><div class="gallery-image-desc">\'.$img_desc.\'</div></li>\';
endforeach;
$image_list .= \'</ul>\';
echo $image_list;
endif;
endif;
?>