此代码删除wordpress本机库,其中显示缩略图并调用永久链接到附件。php,其中它自己显示图像。
下面的代码使用具有有限动画和过渡效果的简单滑块使其成为滑块。
1. Calls the arguments for the transition effect and call the js
$output .= \'
<script type="text/javascript">
jQuery(window).load(function() {
jQuery(".gallery-slider").bjqs({
width : 639,
height : 300,
animtype : "slide",
animduration : 450,
animspeed : 4000,
automatic : false,
showcontrols : true,
centercontrols : false,
nexttext : "Next",
prevtext : "Prev",
showmarkers : false,
centermarkers : false,
keyboardnav : true,
hoverpause : true,
usecaptions : true,
randomstart : true,
responsive : true
});
});
</script>\';
2. Output the slider effect.
$output .= "<div class=\'gallery-slider\' style=\'margin-bottom:10px;\'><ul class=\'bjqs\'>";
$attachments = get_posts( $args );
if ( $attachments )
{
foreach ( $attachments as $attachment )
{
$output .= "<li>";
$output .= "<img src=\'".wp_get_attachment_url( $attachment->ID )."\' />";
$output .= "</li>";
}
$output .= " </ul>";
}
return $output;
}
下面你把它全部放在一起。使用js和参数设置过渡效果。
remove_shortcode( \'gallery\' );
function gallery_filter( $atts, $content = null ) {
extract(shortcode_atts(array(\'gallery_name\' => \'\'), $args));
$args = array(
\'post_type\' => \'attachment\',
\'numberposts\' => 3,
\'post_parent\' => $post->ID,
\'order\' => \'ASC\',
\'orderby\' => \'menu_order\',
\'post_mime_type\' => \'image\'
);
$output .= \'<script type="text/javascript" src="\'. get_bloginfo( \'template_directory\' ) .\'/js/bjqs-1.3.min.js"></script>\';
$output .= \'
<script type="text/javascript">
jQuery(window).load(function() {
jQuery(".gallery-slider").bjqs({
width : 639,
height : 300,
animtype : "slide",
animduration : 450,
animspeed : 4000,
automatic : false,
showcontrols : true,
centercontrols : false,
nexttext : "Next",
prevtext : "Prev",
showmarkers : false,
centermarkers : false,
keyboardnav : true,
hoverpause : true,
usecaptions : true,
randomstart : true,
responsive : true
});
});
</script>\';
$output .= "<div class=\'gallery-slider\' style=\'margin-bottom:10px;\'><ul class=\'bjqs\'>";
$attachments = get_posts( $args );
if ( $attachments )
{
foreach ( $attachments as $attachment )
{
$output .= "<li>";
$output .= "<img src=\'".wp_get_attachment_url( $attachment->ID )."\' />";
$output .= "</li>";
}
$output .= " </ul>";
}
return $output;
}
add_shortcode( \'gallery\' , \'gallery_filter\' );
现在我有一个问题,它输出5个图像,而不是所有3个附件图像。图像重复了两次。任何帮助都将不胜感激,并将更新最终答案。