문제

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.

도움이 되었습니까?

해결책

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');

다른 팁

get all the categories from the database

$cats = get_categories();

// loop through the categries

foreach ($cats as $cat) {

setup the cateogory ID

$cat_id= $cat->term_id;

Make a header for the cateogry

echo "<h2>".$cat->name."</h2>";


query_posts("cat=$cat_id&post_per_page=100");  
if (have_posts()) : while (have_posts()) : the_post(); ?>
    <a href="<?php the_permalink();?>"><?php the_title(); ?></a>
    <?php endwhile; endif; ?>

done our wordpress loop. Will start again for each category

<?php } ?>

done the foreach statement

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 wordpress.stackexchange
scroll top