我需要同时获取帖子缩略图的帖子标题、日期和内容(或摘录),同时分别获取 url 和图像 src。我正在解决这个查询:
SELECT * FROM wp_posts WHERE post_type='post' AND post_status='publish' ORDER BY id DESC LIMIT 5
使用上面的查询,如何获取帖子缩略图?我正在通过这种方式检索所有数据:
<?php
#start a loop that starts $i at 0, and make increase until it's at the number of rows
for($i=0; $i< $num_rows; $i++) {
#assign data to variables, $i is the row number, which increases with each run of the loop
$blog_date = mysql_result($query_result, $i, "post_date");
$blog_title = mysql_result($query_result, $i, "post_title");
$blog_excerpt = mysql_result($query_result, $i, "post_excerpt");
$blog_content = mysql_result($query_result, $i, "post_content");
#$blog_permalink = mysql_result($query_result, $i, "guid"); //use this line for p=11 format.
$blog_permalink = $blog_url . mysql_result($query_result, $i, "post_name"); //combine blog url, with permalink title. Use this for title format
#format date
$blog_date = strtotime($blog_date);
$blog_date = strftime("%b %e", $blog_date);
?>
<div class="post">
<div class="date"><?php echo $blog_date; ?></div>
<h2><a href="<?php echo $blog_permalink; ?>"><?php echo $blog_title; ?></a></h2>
<div class="entry">
<?php echo $blog_excerpt; ?>
</div>
</div>
<?php } #ends loop ?>
谢谢。