Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #987032

    Hello,

    In archives pages, and everytime there’s a post list, I would like to add a class to theses metas :

    <span class="blog-categories minor-meta">
    <a href="#" rel="tag">Category #1</a>
    <a href="#" rel="tag">Tag #2</a>
    <a href="#" rel="tag">Taxonomy #3</a>
    </span>

    Ideally, the category/tag slug, to have something like that :

    <span class="blog-categories minor-meta">
    <a class="category-1" href="#" rel="tag">Category #1</a>
    <a class="tag-2" href="#" rel="tag">Tag #2</a>
    <a class="taxonomy-3" href="#" rel="tag">Taxonomy #3</a>
    </span>

    I saw the <span class=”blog-categories minor-meta”> is defined in the file includes/loop-index.php.
    But not sure how to modify ?

    Do you think it is possible?
    Thanks in advance for your help ? :)

    #987584

    Hey intweb24,

    Yes you could create a custom child theme template. Copy enfold/includes/loop-index.php to our child theme folder (i.e. enfold-child/includes/loop-index.php). Then open up the file and replace:

    
    $cats .= get_the_term_list($the_id, $taxonomy, '', ', ','').' ';
    

    with:

    
                                $cats = get_the_terms($the_id, $taxonomy);
                                $output_cat_links = '';
    
                                if ($cats && ! is_wp_error($cats))
                                {
                                    foreach($cats as $cat)
                                    {
                                        $output_cat_links .= '<a href="'.get_term_link( $cat->slug, $taxonomy) .'" rel="tag" class="'.$cat->slug.'">'.$cat->name.'</a>';
                                    }
    
                                     $cats = $output_cat_links;
                                }
    
    

    I didn’t test the code but someone posted it here: https://wordpress.stackexchange.com/questions/130622/how-to-add-class-on-term-link an the answer was accepted.

    Best regards,
    Dude

    #989542

    oooh sorry I didn’t see your reply !

    Thank you very much, I’m going to try this ! :)

    #989705

    Hi intweb24,

    Please let us know how that worked for you.

    Best regards,
    Victoria

    #989750

    Well, not totally because it doesn’t display all cats and tags.

    I had :

    <span class="blog-categories minor-meta">
    <a href="#" rel="tag">Category #1</a>
    <a href="#" rel="tag">Tag #2</a>
    <a href="#" rel="tag">Taxonomy #3</a>
    </span>

    And now I only have :

    <span class="blog-categories minor-meta">
    <a href="#" rel="tag" class="tag2">Tag #2</a>
    </span>
    #989827

    Hi,

    Try this code instead

    
                                $terms = get_the_terms($the_id, $taxonomy);
                                $output_term_links = '';
    
                                if ($terms && ! is_wp_error($terms))
                                {
                                    foreach($terms as $term)
                                    {
                                        $output_term_links .= '<a href="'.get_term_link( $term->slug, $taxonomy) .'" rel="tag" class="'.$term->slug.'">'.$term->name.'</a>';
                                    }
    
                                     $cats .= $output_term_links;
                                }
    

    Best regards,
    Dude

    #990142

    Thank you very much this is perfect !

    #990399

    Hi intweb24,

    Glad we could help :)

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

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