I want to get selected categories by id (18,31,35). I want the title and the description of the category, each in a separate div like this<div class="category-id"><h2>category title</h2><p>category description</p></div>
I need to be able to add before the loop...
Oleg Butuzov answers:
<?php
$terms = get_terms('category',array('include'=>'60,61,1',));
?>
<?php foreach($terms as $term){?>
<div class="category-id"><h2><?php echo $term->name;?></h2><p><?php echo $term->description;?></p></div>
<? } ?>
Edouard Duplessis answers:
you have to use WP_Query to do that...
<?php
$the_query = new WP_Query(cat=2,6,17,38);
if($the_query->have_posts())
{
while($the_query->have_posts())
{
$the_query->the_post();
echo get_cat_name($id);
echo category_description($id);
}
}
?>
Michael Fields answers:
$terms = get_terms( 'category', 'include=18,31,35' );
if( $terms ) {
foreach( $terms as $term ) {
print "\n\t" . '<div class="category-' . $term->term_id . '"><h2>' . $term->name . '</h2><p>' . $term->description . '</p></div>';
}
}