Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #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 Geers

    #1424858

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

    #1424924

    Hi 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

    #1424972

    just 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));

    #1425192

    Hi,

    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

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.