所以我在https://wordpress.stackexchange.com/questions/49705/a-little-help-cleanup-from-a-real-coder/49712#49712 其中一条评论是不使用query_帖子,而是使用WP_query。所以我做了一些挖掘,并尝试实现它,现在代码没有完全工作。MultiPostThumbnails没有拉动img,我只得到了The\\u post\\u thubnail,没有额外的img。我做错了什么?
function efs_get_slider(){
$slider= \'<div id="ctslider">
<div class="flexslider">
<ul class="slides">\';
$my_posts = new WP_Query();
$efs_query= "post_type=slider-image";
$my_posts->query($efs_query);
if($my_posts->have_posts()) : while ($my_posts->have_posts()) : $my_posts->the_post();
$flexID = $my_posts->ID;
$img1= wp_get_attachment_image( get_post_thumbnail_id($flexID),\'full\',0 );
$imagemain = preg_replace( \'/(width|height)=\\"\\d*\\"\\s/\', "", $img1 );
if (class_exists(\'MultiPostThumbnails\')) {
$image_name = \'feature-image-2\';
if (MultiPostThumbnails::has_post_thumbnail(\'slider-image\', $image_name)) {
$image_id = MultiPostThumbnails::get_post_thumbnail_id(
\'slider-image\',
$image_name,
$flexID
);
$attr = array(\'class\' => "secondaryslider");
$image = wp_get_attachment_image( $image_id, \'full\', false, $attr );
$imagesecondary = preg_replace(
\'/(width|height)=\\"\\d*\\"\\s/\',
"",
$image
);
}
};
$cttitle = get_the_title();
$ctexcerpt = get_the_excerpt();
$slider.=\'<li><div class="fourcol secondaryimg">\'.$imagesecondary.\'</div>\';
$slider.=\'<div class="threecol flex-caption"><h3>\'.
$cttitle.\'</h3><p>\'.$ctexcerpt.\'</p></div>\';
$slider.=\'<div class="fivecol last">\'.$imagemain.\'</div></li>\';
endwhile; endif; wp_reset_postdata();
$slider.= \'</ul>
</div></div>\';
return $slider;
}