Tagged: 

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

    #360622

    Hey 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,
    Ismael

    #600419

    Hi, 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

    #601830

    Hey!


    @komerezo

    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ünter

    #602046

    Thanks for the answer. It doesn’t seems to work, where should I put the code please ?

    #602941

    Hello 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,
    Regards

    #603904

    Hi!

    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ünter

    #689949

    Hi there,

    I’m trying to change it in enfold\includes\loop-index.php but it seems nothing happens.
    could it be another file instead?

    #691089

    Hi!

    Could you please provide a link to the actual blog page? Did you set it to grid layout? If that is the case, you need to modify the config-templatebuilder > avia-shortcodes > postslider.php file.

    Best regards,
    Ismael

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