我使用自定义页面模板创建了一个自定义新闻页面,这是我对最新帖子的查询:
if ( have_posts() ) :
while ( have_posts() ) : the_post();
the_content(); ?>
<div class="line2"></div>
<?php endwhile;
endif;
wp_reset_query(); ?>
<!-- Start latest post -->
<?php $latest_post = get_posts( \'numberposts=5\' ); // Defaults args fetch posts starting with the most recent
foreach( $latest_post as $post ) : setup_postdata( $post ); ?>
<div class="newsthumb">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a>
</div>
<div class="newstitle">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</div>
<div class="postdate-category">
<?php esportsheaven_posted_on(); ?> | <?php the_category(); ?>
</div>
<div class="newscontent">
<?php the_excerpt(); ?>
</div>
<?php endforeach;
wp_reset_query();
最初页面上应该有5篇文章,当站点获得超过5篇文章时,我会添加分页。做这件事最好/最有效的方法是什么?