-
AuthorPosts
-
November 6, 2023 at 4:31 pm #1424800
Hi there,
I made changes to the functions.php file that were showing up on my staging environment but not on the live environment. The difference between these environments is that the staging is on Enfold 5.6.6. and the live environment has already been updated to 5.6.8.
The code I added to functions.php (which I got from a forum post) is as follows. The result I want is to show the categories in a masonry gallery:
add_filter( ‘avf_masonry_loop_prepare’, ‘avf_masonry_loop_prepare_mod’, 10, 2 );
function avf_masonry_loop_prepare_mod( $key, $entries )
{
$class = preg_grep(‘/category/’, $key[‘class’]);
$getstr = str_replace(‘category-‘, ”, implode(‘,’, $class));
$categories = explode(‘,’, $getstr);
$cat = implode(‘,’, array_map(‘ucfirst’, $categories));
foreach ( $key as $post => $value ) {
if ( $post == ‘content’ ) { $value .= “<div class=’av-masonry-categories’>”.$cat.”</div>”; }
$key[$post] = $value;
}
return $key;
}From our development supplier I understand it could mean that the hook is not compatible with the theme’s current version. And that it’s best to ask you for a new hook.
Hope you can help us out!
Best regards,
Rob GeersNovember 7, 2023 at 4:26 am #1424858Hey Volgspot,
Thank you for the inquiry.
The filter still works correctly on our end. Please edit the Masonry element and make sure that the Content > Captions > Element Title and Excerpt settings is set to the very first option (Display title and excerpt).
add_filter( 'avf_masonry_loop_prepare', 'avf_masonry_loop_prepare_mod', 10, 2 ); function avf_masonry_loop_prepare_mod( $key, $entries ) { $class = preg_grep('/category/', $key['class']); $getstr = str_replace('category-', '', implode(',', $class)); $categories = explode(',', $getstr); $cat = implode(',', array_map('ucfirst', $categories)); foreach ( $key as $post => $value ) { if ( $post == 'content' ) { $value .= "<div class='av-masonry-categories'>".$cat."</div>"; } $key[$post] = $value; } return $key; }
Best regards,
IsmaelNovember 7, 2023 at 2:58 pm #1424924Hi Ismael, thanks a lot for the quick reply! It shows the category now, that’s great.
To make it even better I want to ask: it shows the category slug, and I would like it to show the category name. So instead of “Over-het-platform”, I want it to show without the “-“, so like “Over het platform”. It this possible?
And finally: I would like to add a space between the categories. So where it shows
“Overig,Sectornieuws” I would like to show it as
“Overig, Sectornieuws”
Or, even better: “Overig | Sectornieuws”
Is this possible?Thanks in advance!
Rob
November 8, 2023 at 9:39 am #1424972just a little cosmetic correction – always leave a space after punctuation ( even in english :lol )
so replace that one line to – and with pipe:
$cat = implode(' | ', array_map('ucfirst', $categories));
November 10, 2023 at 5:22 am #1425192Hi,
Thank you for the update.
To remove the hyphens after every word, try to replace this line:
$categories = explode(',', $getstr);
with:
$categories = explode(',', str_replace('-', ' ', $getstr));
Please follow @Guenni007’s instructions above to replace commas with pipes.
Best regards,
Ismael -
AuthorPosts
- You must be logged in to reply to this topic.