[resolved] Category Descriptions - displaying all but the first (5 posts)

  1. LingoSam
    Posted 2 years ago #

    I found a loop online that seemed to do exactly what I need : Group posts by a child category together.

    I can't seem to get the category description(s) to work properly though. In this instance it doesn't display the first category description at all, but puts the first description where the second is, the third where the fourth is and so on.

    Could anyone take a look at this and point me in the right direction?
    It would be much appreciated, I know it's very close to working!

    <div id="categories-wrap">
    <?php $cats = get_categories('parent=15&orderby=count'); ?>
    <?php foreach ($cats as $cat) { ?>
    <?php $cat_id= $cat->term_id; ?>
    <div class="category-description-wrap">
    <?php echo '<h2 class="category-title">'.$cat->name.'</h2>';?>
    <div class="category-description <?php echo $cat->name ;?>"><?php echo category_description(); ?></div>
    <div id="" class="category">
    <?php query_posts("cat=$cat_id"); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class="category-product">
    <h3 class="category-product-title"><a href="<?php the_permalink(); ?>"><?php echo get_the_title(); ?></a></h3>
    <p class="category-subtitle"><?php the_field('cf_subtitle'); ?></p>
    <div class="category-thumbnail"><?php the_post_thumbnail('category-thumb'); ?></div>
    <?php endwhile; endif;?>
    <?php } // done the foreach statement ?>	
  2. keesiemeijer
    Posted 2 years ago #

    What happens if you change this:

    <?php echo category_description(); ?>

    to this:

    <?php echo category_description( $cat_id ); ?>


  3. LingoSam
    Posted 2 years ago #

    That works, thank you!

    Someone also pointed out to me that
    <?php $cat->category_description ?>
    will also work in this instance.

  4. keesiemeijer
    Posted 2 years ago #

    Yes it would, but you have to echo it for it to show up:

    <?php echo $cat->category_description; ?>
  5. LingoSam
    Posted 2 years ago #

    Sorry, forgot to add the echo in on it. Thank you for your assistance. This will be a pretty useful loop I can recycle on further projects!

Topic Closed

This topic has been closed to new replies.

About this Topic