WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. LingoSam
    Member
    Posted 4 months 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>
    
    <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>
    </div> 
    
    <?php endwhile; endif;?>
    </div>
    <?php } // done the foreach statement ?>	
    
    </div>
  2. keesiemeijer
    moderator
    Posted 4 months ago #

    What happens if you change this:

    <?php echo category_description(); ?>

    to this:

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

    http://codex.wordpress.org/Function_Reference/category_description

  3. LingoSam
    Member
    Posted 4 months ago #

    That works, thank you!

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

  4. keesiemeijer
    moderator
    Posted 4 months ago #

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

    <?php echo $cat->category_description; ?>
  5. LingoSam
    Member
    Posted 4 months 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!

Reply

You must log in to post.

About this Topic