你可以试试这个
<?php
// get all the categories
$cats = get_categories();
// loop through the categries
foreach ($cats as $cat)
{
// Get the cateogory ID
$cat_id= $cat->term_id;
//Header for the cateogry
echo "<h2>".$cat->name."</h2>";
// Make a custom wordpress query
query_posts("cat=$cat_id&post_per_page=12");
// start wordpress loop
if (have_posts()) : while (have_posts()) : the_post();
?>
<a href="<?php the_permalink();?>"><?php the_title(); ?></a>
<?php
echo '<hr/>';
endwhile;
endif; // End of WordPress loop
} // End of foreach loop through category
?>
如果您只想获得一个类别(驱动程序),那么
<?php
$cat_name = 'drivers';
$term = get_term_by('name', $cat_name, 'category');
$cat_id=$term->term_id;
query_posts("cat=$cat_id&post_per_page=12");
// start wordpress loop
if (have_posts()) : while (have_posts()) : the_post();
?>
<a href="<?php the_permalink();?>"><?php the_title(); ?></a>
<?php
echo '<hr/>';
endwhile;
endif;
?>
可能这个可以帮助你
<?php
$cat_names = array('team1', 'team2', 'team3');
foreach($cat_names as $cat)
{
$term = get_term_by('name', $cat, 'category');
$cat_id=$term->term_id;
query_posts("cat=$cat_id&post_per_page=12");
// start wordpress loop
if (have_posts()) : while (have_posts()) : the_post();
?>
<a href="<?php the_permalink();?>"><?php the_title(); ?></a>
<?php
echo '<hr/>';
endwhile;
endif;
}
?>