Tagged: blog posts, category hook, hook, portfolio grid
-
AuthorPosts
-
March 1, 2023 at 3:46 pm #1399688
Hi Support,
I am using the Blog Posts Content Element, is there a hook I can use to include the post categories for each post after the blog post thumbnail?
I have done something similar for the Portfolio Grid by copying that component file to my shortcodes folder and modifying the portfolio.php file. I wonder if there is a hook for this before a modify this component though.
While looking into this if there is a similar hook for the portfolio grid to output the posts associated portfolio categories that would be useful to know.
Thanks
SeanMarch 2, 2023 at 8:04 am #1399754Hi Sean,
Please add this PHP code/snippet in functions.php of your child theme, if you’re not using a child theme then you can use plugin like WPCode to insert the PHP code:
add_filter('avf_postslider_show_catergories', 'avf_postslider_show_catergories_mod', 10, 1); function avf_postslider_show_catergories_mod($category) { $show_cats = 'show_business'; return $show_cats; }
Hope it helps.
Best regards,
NikkoMarch 2, 2023 at 6:01 pm #1399863Hi Nikko,
Thank you so much for this code snippet that has worked just as I wanted.
Is there a way to modify that function to output a class to the a tag including the category name in it? so it outputs from this:
<span class="blog-categories minor-meta"><a href="/announcement/" rel="tag">Announcement</a>, <a href="/events/" rel="tag">Events</a> </span>
to this:
<span class="blog-categories minor-meta"><a class="announcement" href="/announcement/" rel="tag">Announcement</a>, <a class="events" href="/events/" rel="tag">Events</a> </span>
Currently, I am targeting the href to style this component, but would rather a class, no biggie if not :)
a[href="/events/"] { background-color: #1E65A7; }
Thanks
SeanMarch 3, 2023 at 6:06 am #1399930Hi Sean,
You will need a child theme for this, if you don’t have one yet, please download it and find instructions here: https://kriesi.at/documentation/enfold/child-theme/ then do the following steps:
1. Add this code in the functions.php of your child theme (if you already have a child theme, just add this if this function if it is not yet added to the child theme):add_filter('avia_load_shortcodes', 'avia_include_shortcode_template', 15, 1); function avia_include_shortcode_template($paths) { $template_url = get_stylesheet_directory(); array_unshift($paths, $template_url.'/shortcodes/'); return $paths; }
2. Add this as well in the functions.php of the child theme:
function get_the_term_list_mod( $post_id, $taxonomy, $before = '', $sep = '', $after = '' ) { $terms = get_the_terms( $post_id, $taxonomy ); if ( is_wp_error( $terms ) ) { return $terms; } if ( empty( $terms ) ) { return false; } $links = array(); foreach ( $terms as $term ) { $link = get_term_link( $term, $taxonomy ); if ( is_wp_error( $link ) ) { return $link; } $links[] = '<a href="' . esc_url( $link ) . '" class="' . $taxonomy . '" rel="tag">' . $term->name . '</a>'; } $term_links = apply_filters( "term_links-{$taxonomy}", $links ); return $before . implode( $sep, $term_links ) . $after; }
3. Add a new folder to the child theme and call it shortcodes
4. Copy postslider folder (from the parent theme) wp-content/themes/enfold/config-templatebuilder/avia-shortcodes/ to the newly created shortcodes folder.
5. Edit wp-content/enfold-child/shortcodes/postslider/postslider.php (line 969)
$cats .= get_the_term_list( $the_id, $taxonomy, '', ', ', '' ) . ' ';
replace it with:
$cats .= get_the_term_list_mod( $the_id, $taxonomy, '', ', ', '' ) . ' ';
Hope this helps.
For further information on how to Add or Override Elements in Avia Layout Builder, please check our documentation: https://kriesi.at/documentation/enfold/intro-to-layout-builder/#add-elements-to-alb
Best regards,
Nikko -
AuthorPosts
- You must be logged in to reply to this topic.