[英]wp_query - limit number od posts, and pages
好的,我創建所有帖子頁面視圖,並堅持循環。 這是wp_query:
<?php if ( ! is_single() ) : ?>
<div class="entry-content">
<?php
$first_articles = new WP_Query(
array(
'posts_per_page' => 2,
'numberposts' => 2,
'category_name' => 'artykuly',
'order' => 'DESC',
)
);
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'twentyseventeen' ),
'after' => '</div>',
'link_before' => '<span class="page-number">',
'link_after' => '</span>',
) );
?>
<?php if ( $first_articles->have_posts() ) : while ( $first_articles->have_posts() ) : $first_articles->the_post(); ?>
<div class="kat-img" style="background: url('<?php the_post_thumbnail_url(); ?>')">
<div><?php the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' ); ?></div>
<div><?php echo excerpt(10); ?></div>
<div><?php echo get_the_date(); ?></div>
<div><?php echo the_tags( '<ul><li>', '</li><li>', '</li></ul>' ); ?></div>
</div>
<?php endwhile; endif; wp_reset_query(); ?>
</div><!-- .entry-content -->
<?php endif; ?>
這是content.php中的代碼(僅此而已),此循環的問題是它顯示2個最新發布,但是這2個最新發布循環被克隆並顯示6次。 問題出在哪兒? 我是否應該為此循環添加更多限制? 我想只顯示一次2個最新帖子。
外部文件中很可能還有另一個循環,例如archive.php,它用於顯示帖子。
可以直接在archive.php或category.php中添加此代碼,也可以從這些文件中刪除其他循環。
同樣從wp查詢中刪除'numberposts' => 2
,不需要它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.