Tagged: 

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #279829

    Hello,

    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.

    #280427

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

    #283379

    Hi 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');
    #283390

    Hi!

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

    #877106

    Hello there, i want to add a category class to the portfolio ajax preview, is that possible?

    #878267

    Hi mjpschouten,

    Could you explain a bit more where you want to add the category?

    Best regards,
    Victoria

    #879009

    Well, 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”&gt;
    <div class=”av_table_col first portfolio-preview-image”>

    #880015

    Hi,

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

    #880338

    Ok 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

    #881054

    Hi,

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

    #882144

    Yes, this works great, thank you so much!!

    #882511

    Hi,

    Awesome. Please feel free to open a new thread if you need anything else. :)

    Best regards,
    Ismael

Viewing 12 posts - 1 through 12 (of 12 total)
  • The topic ‘Enfold Portfolio Category Names’ is closed to new replies.