簡體   English   中英

如何在Wordpress的一頁上獲取具有一個類別的所有帖子?

[英]How to get all posts with one category on one page in wordpress?

我是wordpress的新手。 我已經制作了一個發帖模板。 但是我不知道如何在wordpress中將所有帶有一個類別的帖子發布到一頁上。 誰能幫我解決這個問題?

試試下面的代碼。 您可以添加類別ID並根據需要在每頁上發帖。

 <?php
$catquery = new WP_Query( 'cat=3&posts_per_page=10' );
while($catquery->have_posts()) : $catquery->the_post();
?>
<ul>
<li><h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>

<ul><li><?php the_content(); ?></li>
</ul>
</li>
</ul>
<?php endwhile; ?>

另一種方法:

// The Query
query_posts( array(
      'category_name'  => 'my-category-slug',
      'posts_per_page' => -1
) ); 

// The Loop
while ( have_posts() ) : the_post();
    echo '<li>';
        the_title();
    echo '</li>';
endwhile;

// Reset Query
wp_reset_query();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM