2013-05-02 73 views
0

我需要將帖子縮略圖的帖子標題,日期和內容(或摘錄)全部放在一起,同時分別獲取url和圖片src。我正在解決這個查詢:如何在Wordpress之外獲取張貼縮略圖?

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 ?> 

謝謝。

回答

0

可以使用WP_QueryWordPress就像

<?php 
require('your_wordpress_root_folder/wp-load.php'); 
$args = array(
    'post_status' => 'publish', 
    'post_type' => 'post', 
    'posts_per_page' => 5 
); 
$query = new WP_Query($args); 
while ($query->have_posts()) : $query->the_post(); 
?> 
    <h1><a href="<?php the_permalink() ?>"><?php the_title() ?></a></h1> 
<?php if (has_post_thumbnail()) : ?> 
    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" > 
<?php the_post_thumbnail() ?></a> 
<?php 
    endif; 
endwhile; 
+0

的問題是:我需要從另一個域的安裝,完全超出的位置,我需要找回的職位得到職位。 – joaogdesigner 2013-05-02 21:15:35

+0

[檢查此答案](http://stackoverflow.com/questions/12589025/how-to-pull-posts-from-wordpress-to-other-non-wordpress-site-on-different-hostin)。 – 2013-05-02 21:35:45

相關問題