-
AuthorPosts
-
July 2, 2017 at 3:26 am #815466
Hello,
I found this code in loop index, however i can’t figure out how to display only the first taxonomy of the post and exclude all others separated by commas
I want to look it like this:
February 24, 2016 /0 Comments / in Taxonomy / by UserInstead of
February 24, 2016 / 0 Comments / in Taxonomy taxonomy1, taxonmy2, taxnomy3, , , etc / by UserANy suggestion
Thanks!July 2, 2017 at 9:29 am #815489Hey road66,
Perhaps this will help: https://kriesi.at/support/topic/show-only-one-first-category-in-blog-single-post/#post-360622
Or: https://kriesi.at/support/topic/show-only-one-category-in-metadescription/#post-324740Best regards,
MikeJuly 2, 2017 at 6:28 pm #815588Hey Mike,
I ‘ve tried all of these options before posting here, none of those worked for me.
The most worked one was this :$cats = explode(‘,’, $cats);
if(!empty($cats))
{
echo ‘<span class=”blog-categories minor-meta”>’.__(‘in’,’avia_framework’).” “;
echo $cats[0];
echo ‘</span><span class=”text-sep text-sep-cat”>/</span>’;
}However, it’s messing up on the frontend :
Looks like this:
————————————-
in Taxonomy taxonmy1/
Title of the post
February 24, 2016/ 1 Comment /in Array / by User
———————————-Thanks.
July 4, 2017 at 4:58 am #816139This code works, however it’s showing up 2 taxonomies, how to output only one Taxonomy?
$taxonomies = get_object_taxonomies(get_post_type($the_id));
$cats = ”;
$excluded_taxonomies = apply_filters(‘avf_exclude_taxonomies’, array(‘post_tag’,’post_format’), get_post_type($the_id), $the_id);if(!empty($taxonomies))
{
foreach($taxonomies as $taxonomy)
{
if(!in_array($taxonomy, $excluded_taxonomies))
{
$cats .= get_the_term_list($the_id, $taxonomy, ”, ‘, ‘,”).’ ‘;
}
}
}$cats = explode(‘,’, $cats);
if(!empty($cats))
{
echo ‘<span class=”blog-categories minor-meta”>’.__(‘in’,’avia_framework’).” “;
echo $cats[0];
echo ‘</span><span class=”text-sep text-sep-cat”>/</span>’;
}- This reply was modified 7 years, 5 months ago by road66.
July 4, 2017 at 6:38 pm #816446$cats = explode(‘,’, $cats); works only on comma separated taxonomy
I’m getting this: Taxonomy[space]taxonomy2July 6, 2017 at 9:24 am #817100Hi road66,
Try this
$cats = explode(' ', $cats);
If you need further assistance please let us know.
Best regards,
Victoria -
AuthorPosts
- You must be logged in to reply to this topic.