I am trying to show all posts in each category. I've been searching around and it seems I need to have either the category slug or term_id to do so, like the code below.

<?php query_posts('category_name=MyCategory&showposts=9999'); ?>

I'm currently editing the archive.php how to get the slug name?

Thanks.

link|improve this question

75% accept rate
thanks Michael, I was confuse that how to display category wise post on archive.php by query_post, because I am using Magic_fields plugin. really this script help me. Again thaks. – kundan Apr 11 at 6:24
feedback

1 Answer

up vote 0 down vote accepted

to get the category slug of the category archive:

$cat_slug = get_category(get_query_var('cat'))->slug;

alternatively, to get the category ID of the category archive:

$cat_id = get_query_var('cat');
link|improve this answer
Thanks a lot! I really appreciate you help! Just a question: do you know a better way to show all posts than <?php query_posts('category_name=MyCategory&showposts=9999'); ?> Thanks! – Muazam Aug 27 '11 at 15:57
1  
@Muazam showposts parameter is deprecated since 2.1, use posts_per_page with arg -1, also it would be better if you use array for query_posts args: <?php query_posts( array( 'category_name' => 'my_category_slug', 'posts_per_page' => -1 ) ); ?> – Mamaduka Aug 27 '11 at 16:08
@Mamaduka Perfect! Thanks a lot! – Muazam Aug 27 '11 at 16:21
@Mamaduka One more question, do you know how to order the result by ID and DESC? – Muazam Aug 27 '11 at 20:03
1  
@Muazam add this two parameters: <?php query_posts( array( 'category_name' => 'my_category_slug', 'orderby' => 'ID', 'order' => 'DESC', 'posts_per_page' => -1 ) ); ?> – Mamaduka Aug 27 '11 at 20:17
feedback

Your Answer

 
or
required, but never shown

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