0

There are over 200 posts tagged with the keyword "Apple."

Each tag page -- example.com/tag/apple/page/2/ -- shows 10 posts.

So there are 20 tag pages.

Is it possible to show all these 200 post (links) in one page? I don't want to show any of the excerpt -- just consolidate all those 200 links in one page.

Appreciate your help!

2
  • do you want example.com/tag/apple/ to show all posts, or a separate page?
    – Milo
    Commented Feb 25, 2013 at 19:02
  • When someone visits the tag page -- example.com/tag/apple -- he/she should be shown all the posts. No pages. Thanks, Milo!
    – Sid
    Commented Feb 25, 2013 at 19:28

2 Answers 2

3

This is what I would consider the correct solution, and is the solution alluded to by Milo's comment (if I am not mistaken).

function alter_ppp_for_tags_wpse_88337($qry) {
  if ( is_tag() && $qry->is_main_query() ) {
    $qry->set('posts_per_page','-1');
  }
}
add_action('pre_get_posts','alter_ppp_for_tags_wpse_88337');

Using query_posts will cause two requests to the database-- the main query, and the query triggered by the use of query_posts. By using a filter on pre_get_posts you alter the main query before posts are fetched and thus only hit the database once.

Reference:

http://codex.wordpress.org/Class_Reference/WP_Query

2
  • 2
    And if you want to target the "apple" tag specifically: if (is_tag( 'apple' ) ). Also, be sure to include && $query->is_main_query() in the conditional. Commented Feb 25, 2013 at 19:47
  • S_ha_dum, you rock! That code works perfectly. Thanks a lot. Also, Chip Bennett, appreciate your response. Boy, you guys are genius. :)
    – Sid
    Commented Feb 26, 2013 at 5:24
-1

Its possible. You need to modify parameters in query_posts(). Use:

query_posts('tag'=>'apple', 'posts_per_page'=>-1)

'nopaging'=>1 can also be used for listing all items. Check Parameters for detail.

4
  • 3
    Do not use query_posts, ever. Modify the main query via pre_get_posts, create additional queries via WP_Query.
    – Milo
    Commented Feb 25, 2013 at 19:10
  • Now I am more confused -- should I follow Nilambar's advice or go through Milo's links. Also, not sure where to add these codes! Appreciate your help.
    – Sid
    Commented Feb 25, 2013 at 19:30
  • You should go through Milo's links. query_posts is pretty much always a bad idea. Just don't use it.
    – s_ha_dum
    Commented Feb 25, 2013 at 19:37
  • Do not use query_posts(), ever, for anything. There is always a better, more appropriate way to modify or create a query. Commented Feb 25, 2013 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.