WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How do i show a custom-taxonomy description in a DIV only when there is a descri (3 posts)

  1. defade
    Member
    Posted 4 years ago #

    Hi...

    I've made some custom taxonomies.. just basic tag clouds for specifics topics on my blog

    I then have made a taxonomy.php template page to show a list of posts connected to each custom tag

    Some of these custom tags will have descriptions, but a lot of them won't

    I'd like to display the descriptions at the top of taxonomy.php pages

    This is easily achieved using this code i found via Google

    <?php echo term_description( '', get_query_var( 'taxonomy' ) ); ?>

    The problem with that code alone is it just prints the description in a basic paragraph

    I need to style the description to make it look pretty etc

    At the moment i have simply wrapped the php code in a div like this

    <div class="tag-desc"><?php echo term_description( '', get_query_var( 'taxonomy' ) ); ?></div>

    This looks perfect when there IS a description for a tag, as can be seen here: Tag with description example

    But this has an unfortunate side effect when you look at a tag with NO description, as seen here: Tag with NO description example (It leaves that horrible looking empty thin black box at the top of the page)

    Could someone that knows coding please tell me how i could call a description nested within a DIV only when there IS a description... and not show the DIV when there is NO description

    I'm sure it must be possible... but i cannot find any help for this

    Many thanks for reading

    -ADE

  2. keesiemeijer
    moderator
    Posted 4 years ago #

    Maybe this will work:

    <?php
    $termDiscription = term_description( '', get_query_var( 'taxonomy' ) );
    if($termDiscription != '') : ?>
    <div class="tag-desc"><?php echo $termDiscription; ?></div>
    <?php endif; ?>
  3. defade
    Member
    Posted 4 years ago #

    You sir... are a legend

    It works perfectly - Thank you very much

Topic Closed

This topic has been closed to new replies.

About this Topic