 
	
		Tagged: enfold
- 
		AuthorPosts
- 
		
			
				
June 17, 2014 at 5:23 am #279829Hello, Is there a way to get the category nice name of a portfolio category, and write that out as a class or id in the body of a portfolio single? I’m in the process of making a portfolio site with 3 pages (Film, Commercial, Art) that each have their own set of portfolio singles (categorized as Film, Commercial, and Art) and I’d like to highlight the Film navbar link whenever a site visitor is viewing a Film Portfolio Single. If I can add those category specific classes to the <html> or <body> element of each page than I can style the corresponding navbar link to be highlighted. June 18, 2014 at 9:22 am #280427Hey juicesandmilks! Yes, I found some tutorials with google when I searched for “wordpress add category name to body class” – i.e. http://bavotasan.com/2011/add-a-posts-category-name-to-body-class-in-wordpress/ Best regards, 
 PeterJune 25, 2014 at 3:22 am #283379Hi Dude, and thanks for the pointer. Unfortunately that bit of code does not work for me. The function is adding a ‘category-‘ class to my body tag, but it either isn’t able to find the category slug, or it isn’t able to add it to the class name: function add_category_name($classes = '') { if(is_single()) { $category = get_the_category(); $classes[] = 'category-'.$category[0]->slug; } return $classes; } add_filter('body_class','add_category_name');June 25, 2014 at 4:21 am #283390Hi! That’s because that code is meant to be used with Posts, try changing it to: function add_category_name($classes = '') { if(is_single()) { $category = get_the_terms($post->ID, 'portfolio_entries'); $classes[] = 'category-'.current($category)->slug; } return $classes; } add_filter('body_class','add_category_name');Regards, 
 JosueNovember 15, 2017 at 3:48 pm #877106Hello there, i want to add a category class to the portfolio ajax preview, is that possible? November 17, 2017 at 7:27 pm #878267Hi mjpschouten, Could you explain a bit more where you want to add the category? Best regards, 
 VictoriaNovember 20, 2017 at 10:25 am #879009Well, want i want to achieve is to have an image of the parent category showing in the portfolio ajax preview (popup). 
 In the header of this popup.I think i can do this with CSS, so i want to add a category class, like the CATEGORYNAME to this popup per product. 
 For example:
 <div class=”portfolio_preview_container open_container” data-portfolio-id=”1″ style=””>
 <div class=”portfolio-details-inner”>
 <div class=”ajax_slide ajax_slide_200 open_slide” data-slide-id=”200″>
 <article class=”inner_slide CATEGORYNAME” itemscope=”itemscope” itemtype=”https://schema.org/CreativeWork”>
 <div class=”av_table_col first portfolio-preview-image”>November 22, 2017 at 4:14 am #880015Hi, That is possible but you have to modify the config-templatebuilder > avia-shortcodes > portfolio.php file. Look for this code around line 820. $output .= "<article class='inner_slide $nogalleryclass' ".avia_markup_helper(array('context' => 'entry','echo'=>false, 'id'=>$id, 'custom_markup'=>$this->atts['custom_markup'])).">";Best regards, 
 IsmaelfNovember 22, 2017 at 4:00 pm #880338Ok thank you, you helped me on the way, so now i am trying to get the category name into this class. 
 Something like:$tags = implode(” “, get_the_terms( get_the_ID(), ‘portfolio_entries’ ) ); $output .= “<article class=’inner_slide $nogalleryclass $tags'” But this is not working, i am getting nothing or an Array November 24, 2017 at 5:53 am #881054Hi, Please replace the line with the following code. $terms = get_the_terms( $id, 'portfolio_entries' ); if ( $terms && ! is_wp_error( $terms ) ) { $terms_link = array(); foreach ( $terms as $term ) { $terms_link[] = $term->slug; } $tags = join( " ", $terms_link ); } $output .= "<article class='inner_slide $tags $nogalleryclass' ".avia_markup_helper(array('context' => 'entry','echo'=>false, 'id'=>$id, 'custom_markup'=>$this->atts['custom_markup'])).">";Best regards, 
 IsmaelNovember 27, 2017 at 10:28 am #882144Yes, this works great, thank you so much!! November 28, 2017 at 5:47 am #882511
- 
		AuthorPosts
- The topic ‘Enfold Portfolio Category Names’ is closed to new replies.
