googlebot
Member
Posted 2 years ago #
I'm working on a theme and on the category page I'm displaying the category description inside a styled div container, however when there's no description available for a certain category this div looks pretty darn ugly all empty, I came up with a rudimentary solution but I'm not sure is the proper way, seems to work though.
<?php if (category_description( $category ) == '') : ?>
<div>
<?php else : ?>
<div class="cat-descr">
<?php endif; ?>
<?php echo category_description( $category ); ?>
</div>
any other idea to beautify the code? :-)
Thanks
Use the Conditional Tags is_category() or 'in_category()` as required in your situation. Also, The Loop article describes styling posts when belonging to different categories.
googlebot
Member
Posted 2 years ago #
mmm, I'm not sure I understand your answer, I mean I "know" about conditional tags and I use them to show posts from categories and so on but couldn't find anything about category description or I missed it...
how would i know and test if a category has a description or not?
In my case (my php skills are somewhat limited) I just guessed that
if category_description was equal to nothing ('') do this else do something else.
The way I have it now it's working but i'm not sure if is the right way to do it :-\
So you saw that article, but did you see this example?
is_category('Stinky Cheeses')
When the archive page for the Category with Name "Stinky Cheeses" is being displayed.
groomedmonkey
Member
Posted 1 year ago #
Don't think you read googlebots's post properly Michel. He is not asking for a conditional dependent on category name but depending on whether a category description exists for the current category. Basically the way he is doing it is basing the conditional on the negative (if description is empty).
Basically I stripped your code down to this googlebot:
<?php if (category_description( $category ) == '') : ?>
<!-- html for when there is no description -->
<?php else : ?>
<!-- html for when there is a description -->
<?php echo category_description( $category ); ?>
<!-- html for when there is a description -->
<?php endif; ?>