2013-05-02 7 views
0

Мне нужно получить заголовок, дату и содержание (или выдержку) эскиза сообщения вместе, одновременно получая URL-адрес и изображение src отдельно. Я вокруг этого запроса:Как получить миниатюры после Wordpress?

SELECT * FROM wp_posts WHERE post_type='post' AND post_status='publish' ORDER BY id DESC LIMIT 5 

Использование запроса выше, как получить также сообщения thumbnail? Я извлекаю все данные таким образом:

<?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_Query вне WordPress так же, как

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

+0

[Отметьте этот ответ] (http://stackoverflow.com/questions/12589025/how-to-pull-posts-from-wordpress-to-other-non-wordpress-site-on-different-hostin). –

Смежные вопросы