如何用php显示上一篇博文?

时间:2017-09-07 22:33:54

标签: php wordpress

我的WP主题中有这个代码,它可以正常工作。但是,当我想显示来自其他网站的最后一篇文章时(例如:www.mag.tabgir.com),它没有显示我博客上的帖子。

如何更改此代码以显示本网站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>

1 个答案:

答案 0 :(得分: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'];
}
相关问题