-
AuthorPosts
-
July 18, 2018 at 3:22 pm #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 ? :)July 19, 2018 at 7:09 pm #987584Hey 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,
DudeJuly 25, 2018 at 8:39 am #989542oooh sorry I didn’t see your reply !
Thank you very much, I’m going to try this ! :)
July 25, 2018 at 2:30 pm #989705Hi intweb24,
Please let us know how that worked for you.
Best regards,
VictoriaJuly 25, 2018 at 3:33 pm #989750Well, 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>
July 25, 2018 at 5:34 pm #989827Hi,
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,
DudeJuly 26, 2018 at 10:17 am #990142Thank you very much this is perfect !
July 26, 2018 at 8:33 pm #990399Hi intweb24,
Glad we could help :)
If you need further assistance please let us know.
Best regards,
Victoria -
AuthorPosts
- You must be logged in to reply to this topic.