Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #29063

    Hi guys,

    I was wondering if there is a way to add the category of a blog post to the Blog Posts content element. I would like to make a visual distinction between different categories. If I inspect the generated html, I do see the post ID as a CSS class (e.g. post-entry-184) but not the category.

    Can I modify a php template and add this category to get this done?

    Best regards,

    Bas

    #139600

    Hi Bas,

    The posts already have a category class on them actually. For example, open up this page: http://kriesi.at/themes/enfold/2012/12/12/lorem-ipsum-dolor-sit-amet-consectetuer-adipiscing-elit-aenean-commodo-ligula-eget-dolor-aenean-massa/

    In dev tools add this css:

    #top.single-post .category-images {
    background: #333;
    }

    Regards,

    Devin

    #139601

    Hi Devin,

    Thanks for your quick response. Actually I did not mean the single posts, but the so called “Blog Posts” content element when using the Avia Layout Builder:

    E.g. the Recent News item on this page:

    http://kriesi.at/themes/enfold/homepage/home-v4-small-slider/

    Or the Latest News items on this page:

    http://kriesi.at/themes/enfold/homepage/home-v3-3-column-with-blog/

    The div I would like to add a category class to, is the one with the .slide-entry class:

    <div class="slide-entry flex_column post-entry post-entry-250 slide-entry-overview slide-loop-1 slide-parity-odd av_one_third first real-thumbnail">

    As you can see, the post ID has already been added as a class… If there is a way to add the category that would be great.

    Regards, Bas

    #139603

    You can easily add it – open up wp-contentthemesenfoldconfig-templatebuilderavia-shortcodespostslider.php and replace

    $output .= "<div class='slide-entry flex_column {$style} {$post_class} {$grid} {$extraClass} {$thumb_class}'>";

    with

    $taxonomies  = get_object_taxonomies(get_post_type($the_id));
    $taxs = array();
    $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))
    {
    $taxs[] = wp_get_post_terms( $the_id, $taxonomy );
    }
    }
    }

    foreach($taxs as $tax)
    {
    foreach($tax as $term)
    {
    $post_class .= ' '.$term->slug.' ';
    }
    }

    $output .= "<div class='slide-entry flex_column {$style} {$post_class} {$grid} {$extraClass} {$thumb_class}'>";

    #164048

    Thanks!!

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Add category as a CSS class to "Blog Posts" content element’ is closed to new replies.