Collect name of category WordPress

0

I'm trying to collect the category name with the following code

<a href="<?php get_cat_name( $cat_id ); ?>"></a>

But I'm not having much success .. another thing is, I have a 4 categories but the code needs to know if you are using category a or b within 4, if you have no category that is either A or B does not show nothing .. if anyone can help me.

    
asked by anonymous 12.02.2017 / 18:20

1 answer

1

The get_cat_name function returns a string as reported in the documentation , and in its line where you place the a tag is not using echo nor <?= to display the name.

<a href="<?php echo get_cat_name( $cat_id ); ?>"></a>

OR

<a href="<?= get_cat_name( $cat_id ); ?>"></a>

With regard to verification you can make a simple if

<a href="<? echo (get_cat_name( $cat_id ) == 'a' || get_cat_name( $cat_id ) == 'b') ? 'exibe o resultado' : ''; ?>"></a>

Replace "exibe o resultado" with the result you want to appear if category a or category b exists

    
12.02.2017 / 20:31