2017-09-07 30 views
0

WPテーマにこのコードがあり、正しく動作します。しかし、別のウェブサイト(例:www.mag.tabgir.com)から最後の投稿を見せたいときは、自分のブログの投稿を表示しません。PHPで最後のブログ投稿を表示するには?

このコードを変更して、このサイトの最終投稿を表示するにはどうすればよいですか?www.mag.tabgir.com

<section class="block-blog box"> 
    <header> 
    <h2>recent post</h2> 
    </header> 
    <section class="content"> 
     <?php 
      // The Query 
     query_posts('posts_per_page=3'); 

     // The Loop 
     while (have_posts()) : the_post();?> 

     <article class="clearfix"> 
      <a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_post_thumbnail('blog') ?></a> 
      <h1 class="title"><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title(); ?></a></h1> 
      <span><?php the_time('d/M/Y') ?></span> 
     </article> 
     <?php endwhile; 

     // Reset Query 
     wp_reset_query(); 
     ?> 
     <a href="https://mag.tabgir.com/" class="blog">see more</a> 
    </section> 
</section> 

答えて

0

以下は、正しく動作し、ローカルでテストされているコードです。

$args = array(
    'numberposts' => 1,// increase the number if you wish to display 2 latest 
    'orderby' => 'post_date', 
    'order' => 'DESC', 
    'post_type' => 'post', 
    'post_status' => 'publish', 
    'suppress_filters' => true 
); 

$recent_posts = wp_get_recent_posts($args, ARRAY_A); 
foreach ($recent_posts as $result) 
{ 
    echo 'Title : '.$result['post_title'].'<br/>'; 
    echo 'content : '.$result['post_content']; 
} 
関連する問題