Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #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 User

    Instead of
    February 24, 2016 / 0 Comments / in Taxonomy taxonomy1, taxonmy2, taxnomy3, , , etc / by User

    ANy suggestion
    Thanks!

    #815489
    #815588

    Hey 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.

    #816139

    This 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.
    #816446

    $cats = explode(‘,’, $cats); works only on comma separated taxonomy
    I’m getting this: Taxonomy[space]taxonomy2

    #817100

    Hi road66,

    Try this

    
    $cats = explode(' ', $cats);
    

    If you need further assistance please let us know.
    Best regards,
    Victoria

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.