Slider Revolution WP
09.06.2016
This method works by adding a specific tag to the posts you want to feature.
For this example, I’ve created a new tag called “featured”, and this is what we will check for in the PHP code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
add_filter('essgrid_modify_posts', 'eg_modify_post', 10, 2); function eg_modify_post($posts, $grid_id){ /* Your grid's ID can be found where your grid's are listed in the plugin's main admin page. */ $your_grid_id = 1; $your_featured_tag = 'featured'; /* *************************************** */ /* no need to modify any of the below code */ /* *************************************** */ if($grid_id != $your_grid_id) return $posts; $stickys = array(); $regular = array(); foreach($posts as $post) { if(!has_tag($your_featured_tag, $post['ID'])) $regular[] = $post; else $stickys[] = $post; } return array_merge($stickys, $regular); } |
Change this line:
1 2 3 |
if(!has_tag($your_featured_tag, $post['ID'])) $regular[] = $post; |
to this:
1 2 3 |
if(!has_term($your_featured_tag, 'your_cpt_slug_name', $post['ID'])) $regular[] = $post; |
This method will allow you to always show posts marked as “sticky” first in your grid.
On the surface this may seem like the obvious choice, but it’s important to keep in mind that setting a post as a “sticky” means it will also be shown first in your regular blog. So if you only want to show certain posts first in your grid only, use the “tag” method above instead.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
add_filter('essgrid_modify_posts', 'eg_modify_post', 10, 2); function eg_modify_post($posts, $grid_id){ /* Your grid's ID can be found where your grid's are listed in the plugin's main admin page. */ $your_grid_id = 1; /* *************************************** */ /* no need to modify any of the below code */ /* *************************************** */ if($grid_id != $your_grid_id) return $posts; $stickys = array(); $regular = array(); foreach($posts as $post) { if(!is_sticky($post['ID'])) $regular[] = $post; else $stickys[] = $post; } return array_merge($stickys, $regular); } |