如果我正确理解了您的问题,您希望检索每篇文章的第一个附加图像(&M);使用缩略图大小,而不是解析嵌入图像的内容&;使用timthumb?
如果是这样,请在“媒体选项”页面中将缩略图大小设置为所需大小(60x60),确保已按所需顺序拖放附件,然后使用以下代码(请注意,我不喜欢query\\u帖子,我更喜欢使用get\\u帖子)。
$args = array(
\'meta_key\' => \'views\',
\'orderby\' => \'meta_value_num\',
\'order\' => \'DESC\',
\'posts_per_page\' => 9
);
$popular_posts = get_posts( $args );
if ( $popular_posts ) {
echo \'<h2>Popular Posts</h2>\';
echo \'<ul>\';
foreach ( $popular_posts as $popular_post ) {
$kids_args = array(
\'post_parent\' => $popular_post->ID,
\'post_type\' => \'attachment\',
\'post_status\' => null,
\'post_mime_type\' => \'image\',
\'orderby\' => \'menu_order\',
\'order\' => \'ASC\',
\'posts_per_page\' => 1
);
$kids = get_posts( $kids_args );
echo \'<li>\';
if ( $kids ) {
foreach ( $kids as $kid ) {
$img = wp_get_attachment_image_src( $kid->ID );
printf( \'<a href="%s" title="%s"><img src="%s" width="%s" height="%s"></a>\',
get_permalink( $popular_post->ID ),
esc_attr( get_the_title( $popular_post->ID ) ),
$img[0],
$img[1],
$img[2]
);
}
} else {
printf( \'<a href="%s" title="%s"><img src="%s" width="%s" height="%s"></a>\',
get_permalink( $popular_post->ID ),
esc_attr( get_the_title( $popular_post->ID ) ),
get_bloginfo( \'template_url\' ) . \'/images/default.jpg\',
60,
60
);
}
echo \'</li>\';
}
echo \'</ul>\';
}
我是凭记忆写的,现在无法测试,所以希望它能工作!