WordPress 如何显示最近更新的页面和帖子


wordpress how to display recently updated pages and posts

我很难把它实现到我的主题中。现在,主题仅显示最近的帖子。我知道如何显示最近的帖子或页面,但我不知道如何同时显示它们。

这是当前循环代码:

$nr_posts = ($sd_data['home_sidebar_hide'] == 1) ? $sd_data['home_news_posts_disabled'] : $sd_data['home_news_posts'] ;
$i = 0;
$args = array('post_type' => 'post',
                'posts_per_page' => $nr_posts,
                'order'          => 'DESC',
                'orderby'        => 'date',
                'post_status'    => 'publish'
            );
query_posts( $args );
if( have_posts() ) : while ( have_posts() ) : the_post(); $i++;
$margin_nr = ($sd_data['home_sidebar_hide'] == 1) ? 5 : 4; 
if( $i == 1) {
$class = 'span3 alpha';
} else if( $i == $margin_nr) {
$i = 0;
$i++;
$class = 'span3 alpha';
} else $class = 'span3';
?>
<div class="<?php echo $class; ?>">
<div class="news-item">
<?php if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())  ) : ?>
<?php the_post_thumbnail('recent-blog'); ?>
<?php endif; ?>
<h3><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php the_title(); ?>
</a></h3>
<p><?php echo substr(get_the_excerpt(), 0, 50); ?>...</p>
<div class="news-meta clearfix"> <span class="news-date">
<?php the_time(get_option('date_format')); ?>
</span> <span class="news-comments">
<?php comments_popup_link( '0', '1', '%', 'comments-link', 'c'); ?>
</span> <span class="news-rating"><?php echo sd_post_like_link(get_the_ID()); ?></span>         </div>
</div>
</div>
<?php endwhile; wp_reset_query(); endif; ?>

更改

$args = array('post_type' => 'post',
                'posts_per_page' => $nr_posts,
                'order'          => 'DESC',
                'orderby'        => 'date',
                'post_status'    => 'publish'
            );

$args = array('post_type' => array('post','page'),
                'posts_per_page' => $nr_posts,
                'order'          => 'DESC',
                'orderby'        => 'date',
                'post_status'    => 'publish'
            );

参考此处了解更多WP查询