Translated from our Japanese archive. Dates, product names and examples reflect the original article; this is not an updated product or service recommendation.

A note on displaying posts from multiple categories on a static WordPress page.

<?php $paged = get_query_var(‘paged’); ?>
<?php query_posts(“posts&paged=$paged&cat=2,3&showposts=5″); ?>

<?php if (have_posts()) : while(have_posts()) : the_post(); ?>
<?php
$category = get_the_category();
$cat_id = $category[0]->cat_ID;
$cat_name = $category[0]->cat_name;
$cat_slug = $category[0]->category_nicename;
?>
<li><img src=”<?php echo get_template_directory_uri(); ?>/img/index/icon_top_<?php echo $cat_slug; ?>.png” class=”mr20″><?php echo $cat->category_nicename; ?><span class=”mr20″><?php the_time(‘Y/n/j’); ?></span><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li>

<?php endwhile; ?>
<?php else: ?>
<?php endif; ?>

Double Factory

About the author

Double Factory

Designer, web consultant and sales representative. Former part-time lecturer at the University of Electro-Communications, with 15 years of web production experience as described in the original profile. Gained early experience at a production company in New York. Studies web production to deliver results. Representative Director of Double Factory.

Published: 2022/3/28    Updated: 2024/8/18