Tagged: categories
-
AuthorPosts
-
November 30, 2014 at 9:57 am #360258
Hi
Under the single post title, I would like to show only one category, I assume it will be the first one?
How can I do that?
I found the code in includes/index.php$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">'.__('in','avia_framework')." "; echo $cats; echo '</span><span class="text-sep text-sep-cat">/</span>'; }
Thanks
- This topic was modified 9 years, 11 months ago by website2create.
December 1, 2014 at 6:39 am #360622Hey website2create!
Thank you for using Enfold.
You can replace the code with 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, '', ', ','').' '; } } } $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>'; }
Or this:
$categories = get_the_category($the_id); if(!empty($categories)) { echo '<span class="blog-categories minor-meta">'.__('in','avia_framework')." "; echo $categories[0]->cat_name; echo '</span><span class="text-sep text-sep-cat">/</span>'; }
Or this:
$categories = get_the_category($the_id); foreach($categories as $category) { $category = '<a href="'.get_category_link( $category->term_id ).'">'.$category->cat_name.'</a>'; } if(!empty($categories)) { echo '<span class="blog-categories minor-meta">'.__('in','avia_framework')." "; echo $category; echo '</span><span class="text-sep text-sep-cat">/</span>'; }
Best regards,
IsmaelMarch 18, 2016 at 5:17 pm #600419Hi, I have an issue and I think the topic is fine.
I have 100+ categories on my website. Every post has 2 categories : one is specific (A, B, C, D…) and the other one is common : cat_1 or cat_2.
I would like to exclude cat_1 and cat_2 from the title, and only show the other categories. Is that possible ? I know the IDs of the 2 categories I want to exclude.Thanks a lot for your support
March 22, 2016 at 12:34 pm #601830Hey!
Try the following code:
$categories = get_the_category($the_id); $skip_ids = array( 15, 20 ); // enter the id's to skip $first = true; if( ! empty( $categories ) ) { foreach($categories as $category) { if( ! in_array( $category->term_id, $skip_ids ) ) { if( $first ) { echo '<span class="blog-categories minor-meta">'.__('in','avia_framework')." "; $first = false; } $category = '<a href="'.get_category_link( $category->term_id ).'">'.$category->cat_name.'</a>'; echo '</span><span class="text-sep text-sep-cat">/</span>'; } } }
Regards,
GünterMarch 22, 2016 at 6:03 pm #602046Thanks for the answer. It doesn’t seems to work, where should I put the code please ?
March 24, 2016 at 11:41 am #602941Hello Günter, could you please answer my question ? I am webmaster and very, very bad at coding…
Also you wrote :
if( ! empty( $categories ) )I searched my loop-index.php and I mostly have :
if(!empty($cats))Is that a mistake ?
Thanks again for your answer,
RegardsMarch 28, 2016 at 10:38 am #603904Hi!
Thank you for coming back and sorry for the late reply..
With Enfold 3.5.1:
Goto file enfold\includes\loop-index.php line 157- 171:
$taxonomies = get_object_taxonomies(get_post_type($the_id)); $cats = ''; $excluded_taxonomies = array_merge( get_taxonomies( array( 'public' => false ) ), array('post_tag','post_format') ); $excluded_taxonomies = apply_filters('avf_exclude_taxonomies', $excluded_taxonomies, 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, '', ', ','').' '; } } }
and replace this with:
$taxonomies = get_object_taxonomies(get_post_type($the_id)); $cats = ''; $excluded_taxonomies = array_merge( get_taxonomies( array( 'public' => false ) ), array('post_tag','post_format') ); $excluded_taxonomies = apply_filters('avf_exclude_taxonomies', $excluded_taxonomies, get_post_type($the_id), $the_id); $cat_links = array(); $skip_ids = array( 16, 20 ); // enter the term_id's to skip if(!empty($taxonomies)) { foreach($taxonomies as $taxonomy) { if(!in_array($taxonomy, $excluded_taxonomies)) { // $cats .= get_the_term_list($the_id, $taxonomy, '', ', ','').' '; $terms = get_the_terms( $the_id, $taxonomy ); if ( is_wp_error( $terms ) ) { continue; } if ( empty( $terms ) ) { continue; } foreach ( $terms as $term ) { if( in_array( $term->term_id, $skip_ids ) ) { continue; } $link = get_term_link( $term, $taxonomy ); if ( is_wp_error( $link ) ) { continue; } $cat_links[] = '<a href="' . esc_url( $link ) . '" rel="tag">' . $term->name . '</a>'; } } } } if( ! empty( $cat_links) ) { $cats = implode( ', ', $cat_links ); }
Cheers!
GünterSeptember 21, 2016 at 5:57 pm #689949Hi there,
I’m trying to change it in enfold\includes\loop-index.php but it seems nothing happens.
could it be another file instead?September 24, 2016 at 6:52 am #691089 -
AuthorPosts
- You must be logged in to reply to this topic.