-
AuthorPosts
-
July 5, 2022 at 8:49 am #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!
July 5, 2022 at 3:00 pm #1357285Hey 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,
IsmaelJuly 5, 2022 at 3:07 pm #1357286Hi 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.
July 5, 2022 at 5:45 pm #1357307Hi 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!
July 6, 2022 at 4:12 am #1357346Hi,
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,
IsmaelJuly 6, 2022 at 4:18 am #1357347Hi,
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,
IsmaelJuly 6, 2022 at 9:22 am #1357363Thank 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!
July 9, 2022 at 7:30 pm #1357803Hi,
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,
MikeJuly 12, 2022 at 11:34 am #1358058Thank 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?
July 12, 2022 at 12:13 pm #1358071Hi,
Thanks for the screenshot, try changing the “/” and adding the line break in the function, like this:
$output .= '<span data-link="'. get_term_link($category->term_id, $category->taxonomy) .'" class="blog__masonry–categorie">' . esc_html( $category->name ) . ' - </span><br/>';
Best regards,
MikeAugust 25, 2022 at 12:02 pm #1362769Hi 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,
ItaAugust 25, 2022 at 10:59 pm #1362840Hi,
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,
MikeAugust 26, 2022 at 9:17 am #1362861Hi Mike,
Please find the admin-login in the private area.
Chers,
ItaAugust 28, 2022 at 6:06 pm #1362994Hi,
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,
MikeAugust 29, 2022 at 9:56 am #1363020Hi 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,
ItaAugust 29, 2022 at 11:33 am #1363030Hi,
Sorry I didn’t know you wanted two line breaks, please check now.Best regards,
MikeAugust 29, 2022 at 11:35 am #1363032Hi Mike,
Yes, great! But now I only miss the ‘read more’ (can this be added with a short-code in that place?)
Cheers,
ItaAugust 29, 2022 at 11:50 am #1363034August 29, 2022 at 1:17 pm #1363044Hi Mike,
It’s perfect now! Thank you very much!!
Cheers,
ItaAugust 29, 2022 at 6:11 pm #1363090Hi Ita,
I’m glad that Mike could help you :)
Thanks for using Enfold and have a great day!Best regards,
Nikko -
AuthorPosts
- The topic ‘Show category in Masonry gallery with link to overview posts in that category’ is closed to new replies.