WordPress.org

Ready to get started?Download WordPress

Forums

category description isn't displaying in my loop (7 posts)

  1. Pete
    Member
    Posted 3 years ago #

    Can someone tell me why my category description isn't working in this loop?

    Thanks heaps,
    Pete

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    <?php if( get_post_meta($post->ID, "brochure", true) ): ?>
    
    <strong style="text-align:center;" >Download the <?php echo category_description(); ?> PDF Products Brochure <a title="<?php echo category_description(); ?> Brochure.pdf" href="../wp-content/uploads/<?php echo category_description(); ?>.pdf">HERE</a></strong>
    
    <?php else: ?>
    
    <?php endif; ?>			
    
    <?php endwhile; else: ?>
    
    <?php endif; ?>
  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    is that in the category archive?

    if not, you may need to specify a category ID:

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

  3. Pete
    Member
    Posted 3 years ago #

    Nope it's in a single post (hence the loop bit)

    :)

  4. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    if your post has only one category, you could try:

    <?php $cat = wp_get_post_categories($post->ID); $catid = $cat[0]; ?>
    
    <strong style="text-align:center;" >Download the <?php echo category_description(); ?> PDF Products Brochure <a title="<?php echo category_description(); ?> Brochure.pdf" href="../wp-content/uploads/<?php echo category_description($catid); ?>.pdf">HERE</a></strong>

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

  5. Pete
    Member
    Posted 3 years ago #

    Sort of works? This is what it displays
    <p>My Category name</p>

    don't know why it is in <p > tags??

    How do I display the cat slug?

  6. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    wordpress seems to wrap the category description into paragraph tags, by default.

    slug:

    in the loop:

    <?php
    $category = get_the_category();
    $catslug = $category[0]->slug;
    ?>

    http://codex.wordpress.org/Function_Reference/get_the_category#Show_the_First_Category_Name_Only

  7. Pete
    Member
    Posted 3 years ago #

    So it seems!

Topic Closed

This topic has been closed to new replies.

About this Topic