-
AuthorPosts
-
September 22, 2016 at 10:31 pm #690433
I have added a blog grid by shortcode:
[av_blog blog_type='posts' link='category' blog_style='blog-grid' columns='3' contents='title_read_more' content_length='content' preview_mode='custom' image_size='portfolio' items='6' offset='0' paginate='no' conditional='']
In functions.php I have writtenadd_filter('the_posts', 'bump_sticky_posts_to_top'); function bump_sticky_posts_to_top($posts) { foreach($posts as $i => $post) { if(is_sticky($post->ID)) { $stickies[] = $post; unset($posts[$i]); } } if(!empty($stickies)) return array_merge($stickies, $posts); return $posts; }
When I tag a post as sticky, it works as long the post is within the newest 6 posts. Number 7 and higher don’t appear as sticky post. When I set items=’20’ in the shortcode it works for the first 20 posts.
It seems to be a specific blog-grid-problem.When I use e.g. blog_style=’single-big’ instead of blog_style=’blog-grid’ stycky posts work fine in every case.
Please can you help me, to solve this problem.
Best regards,
Günter- This topic was modified 8 years, 2 months ago by günter. Reason: typo
September 23, 2016 at 10:03 pm #691032Hi,
meanwhile I have found a tolerably working solution at WP Codex:add_filter('avia_post_slide_query', 'avia_post_slide_query_mod'); function avia_post_slide_query_mod($query) { $sticky = get_option( 'sticky_posts' ); $query = new WP_Query( 'p=' . $sticky ); return $query; }
But sticky posts increase the number of intended posts per page (items=’6′ + 1 sticky post = 7).
Is there a way to limit the shown posts beside Css-methods?Regards,
GünterSeptember 27, 2016 at 5:43 am #692059Hi,
Thank you for using Enfold.
We tested the code but it’s not working on our end. Please remove it then replace it with the following:
// sticky posts add_filter('avia_post_slide_query', 'avia_post_slide_query_mod', 10, 2); function avia_post_slide_query_mod($query, $params) { $include = array(); $sticky = get_option( 'sticky_posts' ); $args = array( 'taxonomy' => $params['taxonomy'], 'post__not_in' => $sticky, ); $posts = get_posts( $args ); foreach($posts as $post) { $include[] = $post->ID; } $include = array_merge($sticky, $include); // convert values of the $include from string to int function sti($n) { settype($n, 'int'); return $n ; } $include = array_map("sti", $include); $query['post__in'] = $include; $query['posts_per_page'] = 6; $query['orderby'] = 'post__in'; // sort items based on the post__in value return $query; }
Best regards,
IsmaelSeptember 27, 2016 at 8:20 pm #692399Hi Ismael,
thank you for your code. It works fine ad helps me to reduce my effort.
Best Regards,
GünterSeptember 28, 2016 at 9:52 am #692533 -
AuthorPosts
- The topic ‘Sticky Posts in Blog Grid’ is closed to new replies.