게시물을 페이지에 올리는 데 문제가 있습니다. 특정 카테고리의 게시물을 가져 오려고하지만 게시물이로드되면로드가 5 번 표시됩니다. 나는 이미 관리 패널에서 볼 수있는 게시물의 수를 변경하려했지만 게시물의 출력에는 영향을 미치지 않습니다. 사전에쿼리 게시물에서 뉴스 항목을 5 번 출력합니다.
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
query_posts(array ('category_name' => 'nieuwsitem', 'posts_per_page' => 20));
while (have_posts()) : the_post(); ?>
<?php $myposts = get_posts('');
foreach($myposts as $post) :
setup_postdata($post);
?>
<div class="post-item">
<div class="thedate"><?php echo get_the_time('d/m/Y', $post->ID); ?></p></div>
<div class="post-info">
<h2 class="post-title">
<a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>">
<?php the_title(); ?>
</a>
</h2>
</div>
<div class="post-content">
<?php the_content(); ?>
</div>
</div>
<?php endforeach; wp_reset_postdata(); ?>
<?php endwhile; // end of the loop. ?>
</main><!-- #main -->
</div><!-- #primary -->
감사 :
이 내 코드입니다!
. 'get_posts'는 루프를 사용할 필요가 없습니다. 여기에서는 기본 쿼리를 수정하고 해당 게시물 ('while')을 반복하며 각 루프 내에서 각 동작을 가져 오는 각 게시물을 출력하는 다른 foreach 루프를 실행합니다. 그냥 대신 새로운 WP_Query와 간단한 WordPress 루프를 사용하면됩니다. – Ennui
'WP_Query'로 구현 된 것에 대한 답을 참조하십시오. – Ennui