我建议用wordpress的方式来代替sql查询:
$args = array(
\'numberposts\' => 3,
\'offset\' => 0,
\'category\' => put_your_category_id_here,
\'orderby\' => \'post_date\',
\'order\' => \'DESC\',
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
\'suppress_filters\' => true );
$request = wp_get_recent_posts( $args, ARRAY_A );
参考号:
WordPressUpdate : 以下是当您发布帖子时获取缩略图url的方法
$post_thumbnail_id = get_post_thumbnail_id( $post_id );
if($post_thumbnail_id){
$imageurl = wp_get_attachment_url( $post_thumbnail_id );
}
对您上次评论的答复:
foreach( $recent_posts as $recent ){
echo \'<a href="\' . get_permalink($recent["ID"]) . \'" rel="bookmark" title="\' . $recent["post_title"] . \'">
<article>\';
$post_thumbnail_id = get_post_thumbnail_id($recent["ID"]);
if($post_thumbnail_id){
$imageurl = wp_get_attachment_url( $post_thumbnail_id );
echo \'<img src="\' . $imageurl . \'" alt="" class="latest-img" >\';
}
echo \'<img src="\' . get_template_directory_uri() .\'/img/g.png" class="g" width="667" height="266">
<div class="latest-meta">
<time class="hstack white">DATE</time>
<h2 class="white gstack">\' . $recent["post_title"] . \'</h2>
</div>
</article>
</a>\';
}