Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

extra loop before main loop WordPress

  • SOLVED

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...

Answers (3)

2010-06-29

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>
<? } ?>

2010-06-29

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);
}
}
?>



2010-06-29

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