Problem:
The user has a grid view and would like to add a static element(add button) as the last grid cell when the view has results less than 18.
Solution:
The best/easy way is to hook into the view and test how many results it has, if less than 18, we'll inject a default post.
Inside the loop we'll create a condition to display a different content template for that default post.
A sample code to inject the post is:
add_filter( 'wpv_filter_query_post_process', 'jts_inject_draft_promo', 10, 3 ); function jts_inject_draft_promo( $query, $view_settings, $view_id ) { // replace this with the default/draft promo post idate $default_promo_id = 123; if ( $view_id == 784 ) { if ( $query_post_count < 18 ) { $default_promo = get_post( $default_promo_id ); $query->found_post[] = $default_promo; $query->found_count = $query->found_count + 1; } } return $query; }
A sample code to conditionally display a different Elementor template for the default post is:
[wpv-conditional if="( '[wpv-post-id]' eq '123' )" evaluate="false" ] <div class="col-md-2"> [elementor-template id="278"] </div> [/wpv-conditional] [wpv-conditional if="( '[wpv-found-count]' lt '18' )" ] <div class="col-md-2"> [elementor-template id="867"] </div> [/wpv-conditional]
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query_post_process
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | - | - | 9:00 – 13:00 |
14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - | - | 14:00 – 18:00 |
Supporter timezone: Africa/Casablanca (GMT+01:00)
This topic contains 17 réponses, has 2 voix.
Last updated by Ed Il y a 3 années et 10 mois.
Assisted by: Jamal.