-
AuthorPosts
-
May 29, 2024 at 1:38 am #1446898
Hello there, I’m currently using a filter like this to display sticky posts in a blog grid.
This affects all blog grids on the site.
We have many blog grids and only want these sticky posts to display on the home page.
Is there a way to do this?
Thank you!May 29, 2024 at 4:45 am #1446903Hey NCATIT,
Thank you for the inquiry.
You can add a condition at the very top of the avia_post_slide_query_mod function to filter out other pages. Example:
if(!is_home() || !is_front_page()) return $query;
Best regards,
IsmaelMay 29, 2024 at 3:07 pm #1446943Worked a treat! Thank you Ismael!
NCATITMay 29, 2024 at 6:08 pm #1446968Hi,
Great, I’m glad that Ismael could help you out. Please let us know if you should need any further help on the topic, or if we can close it.
Best regards,
RikardJuly 9, 2024 at 9:54 pm #1461726Hello Rikard, I hope all is well.
Upon closer inspection I noticed the sticky posts are showing up on the category pages. i.e. /category/blog/
Is there a way to suppress them from showing at the top of category pages?
Thank you for any advice.
NCATITJuly 10, 2024 at 8:21 am #1461754Hi,
Thank you for the update.
Please try this code in the functions.php file:
function av_exclude_sticky_posts_from_category($query) { if ($query->is_category()) { $query->set('ignore_sticky_posts', true); } } add_action('pre_get_posts', 'av_exclude_sticky_posts_from_category');
Best regards,
IsmaelJuly 10, 2024 at 4:39 pm #1461788Darn that doesn’t seem to work. I think it might have something to do with taxonomy becasue the url I’m trying to suppress sticky posts on looks like this:
/wp-admin/term.php?taxonomy=category&tag_ID=53&post_type=post&wp_http_referer=/wp-admin/edit-tags.php?taxonomy=category
Any ideas? Thank you!July 11, 2024 at 6:31 am #1461814Hi,
Thank you for the update.
Are you trying to suppress the sticky posts on the backend? Category is a type of taxonomy, so the changes above should affect the category pages. We may need to check the actual category page and access the dashboard to properly check the modification. Please provide the login details in the private field.
Best regards,
IsmaelJuly 15, 2024 at 5:01 pm #1462102Hello Ismael, any updates on this? Thank you. :-)
July 16, 2024 at 8:28 am #1462134Hi,
In our previous message, we requested login credentials to access the dashboard. Please provide the details in the private field.
Best regards,
IsmaelJuly 16, 2024 at 3:49 pm #1462166This reply has been marked as private.July 17, 2024 at 8:35 am #1462221Hi,
Thank you for the info.
We edited the functions.php file and adjusted the filter to keep the sticky posts on the front page and disable them on the category pages.
function exclude_sticky_posts_from_category_pages_filter($query) { if (is_admin()) { return $query; } if (is_front_page()) { $include = array(); $sticky = get_option('sticky_posts'); $args = array( 'post__not_in' => $sticky, 'category__in' => array(4, 31, 51, 52), ); $posts = get_posts($args); foreach ($posts as $post) { $include[] = $post->ID; } $include = array_merge($sticky, $include); $include = array_map('intval', $include); $query['post__in'] = $include; $query['orderby'] = 'post__in'; return $query; } if (is_category()) { $sticky_posts = get_option('sticky_posts'); if (!empty($sticky_posts)) { $query['post__not_in'] = $sticky_posts; } } return $query; } add_filter('avia_post_slide_query', 'exclude_sticky_posts_from_category_pages_filter');
Please make sure to delete the cache before checking the pages.
Best regards,
IsmaelJuly 17, 2024 at 7:26 pm #1462306Thank you so much Ismael. I really appreciate it. :-)
July 18, 2024 at 7:33 am #1462344 -
AuthorPosts
- The topic ‘Sticky posts display on home page only’ is closed to new replies.