Viewing 20 posts - 1 through 20 (of 20 total)
  • Author
    Posts
  • #1357254

    I searched and found in support https://kriesi.at/support/topic/masonry-blog-meta-elements/ how to show categories in a Masonry layout.

    However, the category now links to the blog post in question. I would like it to link to an overview of all blog posts in that category, is that possible?

    Many thanks in advance!

    #1357285

    Hey Frans,

    Thank you for the inquiry.

    Where can we check the modification? There are a lot of suggestions in the previous thread and we are not sure which one has been implemented. Please provide the site URL in the private field so that we can check the masonry element.

    Best regards,
    Ismael

    #1357286

    Hi Ismael,

    Here is the link to the relevant staging environment.

    The code I used is:

    /* Categorie tonen in Masonry gallery
    Bron: https://kriesi.at/support/topic/masonry-blog-meta-elements/ */
    add_filter(“avf_masonry_entry_content”, function($content, $entry, $config) {
    $categories = get_the_category($entry[“ID”]);
    $separator = ‘ ‘;
    $output = ”;
    if ( ! empty( $categories ) ) {
    $output .= “<p>”;
    foreach( $categories as $category ) {
    $output .= ‘<span class=”blog__masonry–categorie”>’ . esc_html( $category->name ) . ‘ / </span>’;
    }
    $output .= “</p>”;
    $content = $output . $content;
    }
    return $content;
    }, 10, 3);

    Cheers,
    ita

    • This reply was modified 2 years, 4 months ago by ifranl.
    #1357307

    Hi Ismael,

    I also spent a lot of time today getting the categories above the Masonry gallery to align to the left, with a padding/margin of 200px. So that it starts below the logo.

    I can’t seem to get it to do that though.

    On line 506 of masonry_entries.css it says: .av-masonry-sort {
    text-align: center;
    padding: 20px 40px;
    visibility: hidden;
    overflow: hidden;
    }

    If I set text-align: left; then the categories do get left-aligned. But adjusting the margin or padding has no effect; so neither does this one:

    #top div.container .av-masonry .av-masonry-sort {
    padding: 0px 0px 0px 260px!important;
    }

    I hope you can provide the correct CSS rules to place the categories in the desired location.

    Thanks in advance!

    #1357346

    Hi,

    Thank you for the info.

    To add a link to the categories, please replace the filter with the following code.

    
    add_filter("avf_masonry_entry_content", function($content, $entry, $config) {
        $categories = get_the_category($entry["ID"]);
        $separator = ' ';
        $output = '';
    
        if ( ! empty( $categories ) ) {
            $output .= "<p>";
    
            foreach( $categories as $category ) {
                $output .= '<span data-link="'. get_term_link($category->term_id, $category->taxonomy) .'" class="blog__masonry–categorie">' . esc_html( $category->name ) . ' / </span>';
            }
    
            $output .= "</p>";
    
            $content = $output . $content;
        }
        return $content;
    }, 10, 3);
    
    

    Then add this script below.

    add_action( 'wp_print_footer_scripts', function () { 
        ?>
        <script>
            (function($) {
                $(document).ready(function() {
                    // redirect to the category page
                    $('.av-masonry-entry').on('click', function(e) {
                        e.preventDefault();
                        
                        var link = $(e.target).attr('data-link'); 
    
                        if(link == undefined) {
                            link = $(this).attr('href');       
                        }
    
                        window.location.href = link;
                    });
                });
            })(jQuery);
        </script>
    <?php 
    }, 999 );
    

    Best regards,
    Ismael

    #1357347

    Hi,

    Thank you for the info.

    To add a link to the categories, please replace the filter with the following code.

    
    add_filter("avf_masonry_entry_content", function($content, $entry, $config) {
        $categories = get_the_category($entry["ID"]);
        $separator = ' ';
        $output = '';
    
        if ( ! empty( $categories ) ) {
            $output .= "";
    
            foreach( $categories as $category ) {
                $output .= '<span data-link="'. get_term_link($category->term_id, $category->taxonomy) .'" class="blog__masonry–categorie">' . esc_html( $category->name ) . ' / </span>';
            }
    
            $output .= "";
    
            $content = $output . $content;
        }
        return $content;
    }, 10, 3);
    
    

    Then add this script below.

    add_action( 'wp_print_footer_scripts', function () { 
        ?>
        <script>
            (function($) {
                $(document).ready(function() {
                    // redirect to the category page
                    $('.av-masonry-entry').on('click', function(e) {
                        e.preventDefault();
                        var cat_link = $(e.target).attr('data-link'),
                            link = cat_link == undefined ? $(this).attr('href') : cat_link; 
                             
                        window.location.href = link;
                    });
                });
            })(jQuery);
        </script>
    <?php 
    }, 999 );
    

    Best regards,
    Ismael

    #1357363

    Thank you so much for the code! The category now links to an overview page for that specific category.
    However, on this summary page I don’t see any text from the blog content, if the blog was created in the advanced editor (all blog posts will be created in the advanced editor)
    And how can I change the styling/ layout of that summary page?

    I also see that some of the text behind the category is shown when the post is created in the classic editor. This will require the inclusion of a <br /> somewhere in the snippet?
    In the advanced editor, no text at all from the blog (1st line of blog content) is visible anymore. Could both points be fixed / equalized?

    And could you still help me with moving the category filter to the left:
    On line 506 of masonry_entries.css it says: .av-masonry-sort {
    text-align: center;
    padding: 20px 40px;
    visibility: hidden;
    overflow: hidden;
    }

    If I set text-align: left; then the categories do get left-aligned. But adjusting the margin or padding has no effect; so neither does this one:

    #top div.container .av-masonry .av-masonry-sort {
    padding: 0px 0px 0px 260px!important;
    }

    I hope you can provide the correct CSS rules to place the categories in the desired location.

    Thanks in advance!

    #1357803

    Hi,
    Please note that the post excerpts will not show for posts created with the Advanced Layout Builder, you will need to manually add the excerpts with the Excerpts Option.
    For blog posts there are a few elements that will not show automatically for posts created with the Advanced Layout Builder, typically it is recommended to use the WordPress default editor for posts to take advantage of the automatic features, but you are welcome to manually add the elements such as the social share buttons, the comment form, and the related posts element, along with manually adding your own excerpts, if you wish.
    As for moving the filter to the left with 260px laft padding, this css is working in my test:

    #top .av-masonry-sort {
        text-align: left;
    }
    #top .av-masonry-sort .av-sort-by-term {
        padding: 0px 0px 0px 260px;
    }

    Please see the screenshot in the Private Content area.
    After applying the css, please clear your browser cache and check.

    Best regards,
    Mike

    #1358058

    Thank you for your answers! The alignment of filters above posts is now perfect, thank you!

    I still run into the following:
    1. This excerpt should start on a new line (i.e. 2 x <br /> to the display of categories.

    2. Can I change and/or remove the separator ‘/’ between categories in filter?

    #1358071

    Hi,
    Thanks for the screenshot, try changing the “/” and adding the line break in the function, like this:
    2022-07-12_001.jpg
    $output .= '<span data-link="'. get_term_link($category->term_id, $category->taxonomy) .'" class="blog__masonry–categorie">' . esc_html( $category->name ) . ' - </span><br/>';

    Best regards,
    Mike

    #1362769

    Hi Mike,

    Apologies for my very late response. It is a big project and I have now picked up the blog part again. Your solution makes sure that not only the excerpt text starts on a new line, but also each category.

    The idea is: categories behind/next to each other, then a white line, and then the excerpt text.
    Then another white line, and then the read-onward (can this be added with a short-code in that place?)

    Best regards,
    Ita

    #1362840

    Hi,
    Please include an admin login & a direct link to the page in your screenshot in the Private Content area, so we can examine.

    Best regards,
    Mike

    #1362861

    Hi Mike,

    Please find the admin-login in the private area.

    Chers,
    Ita

    #1362994

    Hi,
    Thanks for the login, I adjusted the function to this:

    add_filter("avf_masonry_entry_content", function($content, $entry, $config) {
        $categories = get_the_category($entry["ID"]);
        $separator = ' ';
        $output = '';
    
        if ( ! empty( $categories ) ) {
            $output .= "";
    
            foreach( $categories as $category ) {
                $output .= '<span data-link="'. get_term_link($category->term_id, $category->taxonomy) .'" class="blog__masonry–categorie">' . esc_html( $category->name ) . ' / </span>';
            }
    
            $output .= "<br/>";
    
            $content = $output . $content;
        }
        return $content;
    
    }, 10, 3);

    please clear your browser cache and check.

    Best regards,
    Mike

    #1363020

    Hi Mike,

    Thanks for the revised snippet! However, I am still missing the following:

    “…. Then another white line, and then the read-onward (can this be added with a short-code in that place?)”

    Can you process that as well?

    Cheers,
    Ita

    #1363030

    Hi,
    Sorry I didn’t know you wanted two line breaks, please check now.

    Best regards,
    Mike

    #1363032

    Hi Mike,
    Yes, great! But now I only miss the ‘read more’ (can this be added with a short-code in that place?)
    Cheers,
    Ita

    #1363034

    Hi,
    The masonry item is already a link so you can’t add another link to it. I added Lees verder > as in other places on your site:
    2022-08-29_054925.jpg

    Best regards,
    Mike

    #1363044

    Hi Mike,

    It’s perfect now! Thank you very much!!

    Cheers,
    Ita

    #1363090

    Hi Ita,

    I’m glad that Mike could help you :)
    Thanks for using Enfold and have a great day!

    Best regards,
    Nikko

Viewing 20 posts - 1 through 20 (of 20 total)
  • The topic ‘Show category in Masonry gallery with link to overview posts in that category’ is closed to new replies.