I'm building a jQuery masonry type gallery in Wordpress, which works off categories. I'm 90% there but need to display the categories in a data-groups tag for it to work. ie:
<div class="project" data-groups='["category1","category2",category3"]'>
I'm using to following function:
function the_category_unlinked($separator = ' ') {
$categories = (array) get_the_category();
$thelist = '';
foreach($categories as $category) {
$thelist .= """ . $category->category_nicename . "",";
}
echo $thelist;
}
with:
<div class="project" data-groups='<?php the_category_unlinked(' '); ?>'>
which works, but this echos out the categories with a comma at the end and breaks the entire working effect:
<div class="project" data-groups='["category1","category2",category3",]'>
What can I do to display these categories as needed? It could also be done using tags if that would work...