get_category, not showing just the NAME of a category AND using comma division
-
Hi,
I run a webmagazine and I have two columns in the home page, one for featured articles and one for the other ones.
Often one article is in more than one category, and I could simply use
<?php the_category(', ') ?>
to display them and divide them with a comma.
BUT I use a category to divide featured and not featured articles easily in the loop, but i want the name (“Feature”) hidden in the when using<?php the_category(', ') ?>
. This is because I want to use this category to divide the articles, but I do not want it to be of public domain.
For this reason I use the following script:<?php foreach((get_the_category()) as $cat) { if (!($cat->cat_name=='Feature')) echo $cat->cat_name . ' ';} ?>
Only problem, no comma between the categories that have to be shown, if I have more than one (eg. “Politics” and “Economical Crisis”).
I changed it to this:<?php foreach((get_the_category()) as $cat) { if (!($cat->cat_name=='Fiori')) echo $cat->cat_name . ', ';} ?>
addid the comma into the brackets.. BUT then it displays the comma even when the category to be displayed is only one (eg. an article only under “Politics”)
What kind of code should I use then, to be able to filter out just the name of the “feature” category, keeping a comma as a divider between the other categories?
- The topic ‘get_category, not showing just the NAME of a category AND using comma division’ is closed to new replies.