-
AuthorPosts
-
September 19, 2024 at 4:10 pm #1467463
Hello,
Advanced Layout Editor -> Content Elements -> Blog Posts -> Blog Style -> Grid Layout.
“Make post sticky” does not change the order of posts in the grid.
1. How to stick important posts first in a grid?
2. How make the order of the posts by date with older posts first?
Thank youSeptember 20, 2024 at 5:18 am #1467511Hey ibuzaev,
Thank you for the inquiry.
1-2.) To allow sticky posts and adjust the order of the items in the grid layout, please add this filter in the functions.php file:
add_filter("avia_post_slide_query", function($query, $params) { $sticky_posts = get_option('sticky_posts'); $include = []; $args = [ 'taxonomy' => $params['taxonomy'], 'post__not_in' => $sticky_posts, 'order' => 'ASC', 'fields' => 'ids', ]; $posts = get_posts($args); $include = array_merge($sticky_posts, $posts); $include = array_map('intval', $include); $query['post__in'] = $include; $query['orderby'] = 'post__in'; $query['order'] = 'ASC'; return $query; }, 10, 2);
Best regards,
IsmaelSeptember 21, 2024 at 2:52 pm #1467566Thank you, Ismael
September 21, 2024 at 2:59 pm #1467567Dear Ismael, your function shows only sticky posts now.
I need to show all posts, sticky first and then date asc.
Could you please correct the function?September 23, 2024 at 5:18 am #1467630Hi,
Thank you for the update.
Where can we check this? Please provide the site URL and login details in the private field. Make sure that the Appearance > Theme File Editor is accessible.
Best regards,
IsmaelSeptember 23, 2024 at 10:30 am #1467647…. it is hard to inspect your page ( i’m not able to read it ;) )
but if you decide to have alot of sticky posts – and have no pagination on showing the blog – there will be no other posts after the sticky ones.
My snippet looks a bit different on merging both ( sticky and include) – don’t know if they are equivalent each other:
function sticky_posts_first($query, $params) { $include = array(); $sticky = get_option( 'sticky_posts' ); $args = array( 'post__not_in' => $sticky, 'order' => 'ASC', 'orderby' => 'date', // here you can influence the orderby option of the non sticky post to your needs 'numberposts' => -1 // if you like to show not only a few ); $posts = get_posts( $args ); foreach($posts as $post) { $include[] = $post->ID; } if ( !is_sticky() ) { $include = array_merge($sticky, $include); }; $query['post__in'] = $include; $query['orderby'] = 'post__in'; return $query; } add_filter('avia_post_slide_query','sticky_posts_first', 10, 2);
maybe you can try that instead
September 23, 2024 at 1:06 pm #1467662Thank you Guenni!
Let me trySeptember 23, 2024 at 1:25 pm #1467665Dear Guenni,
I used your snippet.
https://img.savvyify.com/image/Screenshot-2024-09-23-at-12.17.05.9WML8
Here is a screenshot. So the first three people are sticky (the first row),
the second row with 4-6 persons are not sticky.
That is great.
Now can we sort ASC the sticky too? (there is a date below every photo)
Sincerely yours,
IgorSeptember 23, 2024 at 2:32 pm #1467669thats my comment on the page language – where to find that screenshot page?
if you look to Ismaels code – he placed an order at the end – maybe that will do the job:
function sticky_posts_first($query, $params) { $include = array(); $sticky = get_option( 'sticky_posts' ); $args = array( 'post__not_in' => $sticky, 'order' => 'ASC', 'orderby' => 'date', // here you can influence the orderby option of the non sticky post to your needs 'numberposts' => -1 // if you like to show not only a few ); $posts = get_posts( $args ); foreach($posts as $post) { $include[] = $post->ID; } if ( !is_sticky() ) { $include = array_merge($sticky, $include); }; $query['post__in'] = $include; $query['orderby'] = 'post__in'; $query['order'] = 'ASC'; return $query; } add_filter('avia_post_slide_query','sticky_posts_first', 10, 2);
September 27, 2024 at 6:58 pm #1467976Dear Guenni,
Thanky you for your help.
I added this snippet, but it still does not work as expected.Sticky posts are first as planned, but they are not ordered.
The page is here. https://buzaevclinic.ru/team/
Under the photo there is a date which is language universal.I have the same problem with sticky posts in other types of views (list view with exerpt).
Thank youSeptember 30, 2024 at 4:12 am #1468075 -
AuthorPosts
- You must be logged in to reply to this topic.