Tagged: category
Viewing 3 posts - 1 through 3 (of 3 total)
-
AuthorPosts
-
September 24, 2014 at 1:48 pm #324245
Good afternoon,
I would like to show only one (the first) categorie in the metadesription. I found some code but I can’t make it work.
I’ve got this:
$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, '', ', ','').' '; } } } if(!empty($cats)) { echo '<span class="blog-categories minor-meta">Published '.__('in','avia_framework')." "; echo $cats; } // echo '</span><span class="text-sep text-sep-cat">/</span>'; }
And found this:
if ( $category[0] ) {
echo ‘term_id ) . ‘”>’ . $category[0]->cat_name . ‘ ; }`’Could you give me a hand? Thanks!
September 25, 2014 at 3:26 am #324740Hi InekeWerkt!
Thank you for using Enfold.
Use this instead:
$category = get_the_category(); if(!empty($category)) { echo '<span class="blog-categories minor-meta">'.__('in','avia_framework')." "; echo $category[0]->cat_name;; echo '</span><span class="text-sep text-sep-cat">/</span>'; }
Cheers!
IsmaelSeptember 30, 2014 at 7:26 pm #327529Hi Ismael,
Thanks!
Finally I used this: (to keep the link working)$category = get_the_category(); if(!empty($category)) { echo '<span class="blog-categories minor-meta">Published '.__('in','avia_framework')." "; echo '<a href="' . get_category_link( $category[0]->term_id ) . '">' . $category[0]->cat_name . '</a>'; //echo '</span><span class="text-sep text-sep-cat">/</span>'; } gr. ineke
-
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)
- The topic ‘Show only one category in metadescription’ is closed to new replies.