I’m trying to create <div class="cat-hidden categories"></div> where categories is a list of the categories the current post is posted in.

When just using the_taxonomies(), it outputs something like this:

<div class="cat-hidden Job Type: &lt;a href="http://www.cirkut.net/wp/libertyguide/genre/early-career/"&gt;Early-Career&lt;/a&gt;, &lt;a href="http://www.cirkut.net/wp/libertyguide/genre/internship/"&gt;Internship&lt;/a&gt;, &lt;a href="http://www.cirkut.net/wp/libertyguide/genre/other/"&gt;Other&lt;/a&gt;, and &lt;a href="http://www.cirkut.net/wp/libertyguide/genre/web-developmentit/"&gt;Web Development/IT&lt;/a&gt;."></div>`

Whereas I want it to output something similar to this:

<div class="cat-hidden Early-Career Internship Web-Development/IT"></div>

That means I’m going to also have to parse the categories that are outputted because I need Web Development/IT to be Web-Development/IT or Web-Development-IT. I’m unsure about the / being in there because I think CSS doesn’t allow a /. That’s where you experts come along.

I am very proficient in HTML and CSS, and know some PHP and WordPress, but I don’t know where to begin.

If any more info is needed, please let me know.

Thank you!

2 Answers
2

you can use wp_get_post_terms() to get a list of the post categories and just output the category slug which is already phrased for you, something like this:

//in your loop
echo '<div class="cat-hidden';
$cats = wp_get_post_terms($post->ID,'category');
foreach($cats as $cat){
   echo ' '.$cat->slug;
}
echo '"></div>';

Leave a Reply

Your email address will not be published. Required fields are marked *