简体   繁体   中英

How do I get ALL posts in a category with Wordpress?

This works pretty good except it is limited to 10 posts since my blog is set to show 10 posts maximum.

   $featured_query = new WP_Query('cat=3');

        while( $featured_query->have_posts() ){
            $featured_query->the_post();
            $postcount++;
            ...

How can I override that setting and get ALL posts in that category regardless of the maximum posts setting?

Use showposts=-1 . This will override the defaults posts setting. Per this: http://codex.wordpress.org/Template_Tags/query_posts#Post_.26_Page_Parameters

This is best way to do the list of a particular category..

>  $catPost = get_posts(get_cat_ID("NameOfTheCategory"));

> foreach ($catPost as $post) : setup_postdata($post); ?>
>        <div>
>              <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
>              <p><?php the_content(); ?></p>
>        </div> <?php  endforeach;?>

Thanks MrPhpGuru

query_posts('cat = 3')是否可以满足您的需求?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM