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.
Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.
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)
Ce sujet contient 14 réponses, a 2 voix.
Dernière mise à jour par Il y a 6 années et 9 mois.
Assisté par: Nigel.