Tagged: sticky
-
AuthorPosts
-
July 13, 2016 at 11:07 am #660270
Hello,
When creating a featured image slider that only displays a single post, it does not fetch the first sticky post in the categories chosen, but rather the most recent one. Why, and how can I make it display a sticky post first, if there is any?
- This topic was modified 8 years, 5 months ago by emilbroll.
July 13, 2016 at 10:54 pm #660595Hey emilbroll,
Please send us a temporary admin login so that we can have a closer look. You can post the details in the Private Content section of your reply.
Regards,
RikardJuly 14, 2016 at 1:35 pm #660835The admin part of the site is restricted by a proxy filtering out IPs, and I cannot add other IPs, is there another way that you can help me?
July 18, 2016 at 3:27 pm #662047Hi,
not sure what you mean that’s why it would be best to look at your backend. But can you explain further please? what exactly is the issue about? maybe we could try to reproduce it on our end. Use screenshots to make things clear for us (imgur.com, dropbox).
Best regards,
AndyJuly 19, 2016 at 10:16 am #662384Hey,
Ok, I’ll try to explain – we use a featured image slider as a sort of “header” for our site, with only one slide (so it’s like a color section with an image and a title).
In other elements that display (multiple) blog posts, we can make any sticky posts appear before the other posts (like the expected behavior is, but Enfold doesn’t respect/follow) using this bit of code:
add_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; }
This obviously won’t work on a query that only returns one result – our featured image slider – so we need a more viable solution.
So the question is really, why doesn’t Enfold respect sticky posts (in the way that the most recent sticky post will be displayed first in any case), and how can we ensure it does display the sticky post first in cases where sticky posts are outside of the query bounds (post nr. 11 in query e.g., while query only asks for 4 posts).
July 22, 2016 at 4:20 am #663662Hi,
Thank you for the info. Please add this in the functions.php file:
add_filter('avia_feature_image_slider_query', 'avia_feature_image_slider_query_mod', 10, 1); function avia_feature_image_slider_query_mod($query) { $query['posts_per_page'] = 1; $query['post__in'] = get_option( 'sticky_posts' ); $query['ignore_sticky_posts'] = 1; return $query; }
This will return one of the sticky posts only.
Best regards,
IsmaelAugust 1, 2016 at 12:46 pm #667229Hey, thank you, that works like a charm. :)
August 4, 2016 at 5:00 am #668365 -
AuthorPosts
- The topic ‘Sticky posts in Enfold blog elements’ is closed to new replies.