Problem:
How to display posts of another type (banner ads) every nth iteration of a View output?
Solution:
The outer View displays the main posts.
In the Loop Output section the wpv-loop tag includes a wrap=n attribute and a wpv-item index=n shortcode is used to display a second View (displaying one banner ad) every nth iteration of the outer loop.
The problem is that the same ad will be shown for each iteration. The following code (targeting the second View) will advance the ad shown each time.
add_filter( 'wpv_filter_query_post_process', 'tssupp_iterate_posts', 101, 3 ); function tssupp_iterate_posts( $query, $view_settings, $view_id ){ global $iteration; if ( 158377 == $view_id ) { // Edit ID if ( !isset( $iteration ) ) { $iteration = 0; } $iteration++; if ( $iteration > count( $query->posts ) ) { $iteration = 1; } $query->posts = array( $query->posts[ $iteration - 1 ] ); $query->found_posts = 1; $query->post_count = 1; } return $query; }
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 |
---|---|---|---|---|---|---|
- | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | - |
- | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | - |
Supporter timezone: Europe/London (GMT+00:00)
This topic contains 14 replies, has 2 voices.
Last updated by 6 years, 9 months ago.
Assisted by: Nigel.