WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] If Category have description show in single post.. (7 posts)

  1. onurblank
    Member
    Posted 1 year ago #

    Hello,

    I want to have the category description with in <div></div> on my single post php..

    So every post will show the description of the category it was posted in.

    However some of categories has no description.
    <?php $category = get_the_category(); echo $category[0]->category_description; ?>
    This code was worked finely but i cant put inside div tag on this php code. I want to use If - else php query with using div tags but i cant do it.

    Hope someone can help me out on this one!

    Thank you for your time and effort!
    Regards
    Onur

  2. onurblank
    Member
    Posted 1 year ago #

    Hope someone can help me

  3. vjpo
    Member
    Posted 1 year ago #

    Yes we can :)

    <?php $category = get_the_category();
    if( category_description( $category->cat_ID ) ) : ?>
    <div><?php echo category_description( $category->cat_ID ); ?></div>
    <?php endif; ?>
  4. onurblank
    Member
    Posted 1 year ago #

    @vjpo
    it wanst worked my brother, maybe have a little problem :((

  5. vjpo
    Member
    Posted 1 year ago #

    Sorry, it was little problem, updated

    <?php $category = get_the_category();
    if( category_description( $category[0]->cat_ID ) ) : ?>
    <div><?php echo category_description( $category[0]->cat_ID ); ?></div>
    <?php endif; ?>
  6. onurblank
    Member
    Posted 1 year ago #

    Thank you so much @vjpo. You are perfect .

  7. vjpo
    Member
    Posted 1 year ago #

    Thanks, Onur!

Topic Closed

This topic has been closed to new replies.

About this Topic