This support ticket is created hace 6 años, 11 meses. There's a good chance that you are reading advice that it now obsolete.
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.
Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.
Is it possible to add an adsense script into the middle of a view? My view is displaying 30 posts per page and I'd like to insert an adsense leaderboard ad in the middle of the page.
I tired "index=split2", but it wasn't giving me the desired result, so as a work around I "split the view" by duplicating the view into top and bottom views, and inserted my ad manually in between the two views.
For the top view I displayed the first 16 posts and the following 16 are displayed through the other view. However, my pagination button is no longer visible for the bottom view. Not sure why as the only thing I changed was the limit and offset settings. Display: 16, Skip: first 16.
index=split2 will target the item that falls in the middle of the number of displayed items.
In a View displaying 10 or 11 items (set by a limit or pagination), this will target the 5th issue (because it is a “floored middle”).
That is the correct approach, and it works.
What is not working as you expect on your views?
By splitting the View you seem to have achieved the desired result, but this is also possible with above ShortCode attribute.
Why the pagination is hidden I am not sure. If you insert this second View to another, new page, is the pagination there?
If not, it's either because there is nothing to paginate or because it's removed with JS or CSS (rather JS, since the entire HTML is missing on your end)
Originally I tried using index=split2, but I could not get it to work properly.
This is the markup I tried. Please correct me if I’m wrong, as I would rather use one view instead of two:
<wpv-loop>
[wpv-item index=1]
[wpv-post-title]
[wpv-item index=split2]
[wpv-post-title] + This is the middle
[wpv-item index=other]
[wpv-post-title]
</wpv-loop>
It will output only the post title, unless for the middle item, it will output the post title along with the string "+ This is the middle" or anything else of your choice.
When you use pagination it will split each list into 2, this means, you will see the ad added in the middle item of each pagination page.
When you have 30 posts, and paginate with 10 each, and have a split2 in the loop, then the front end will show 10 items each paginated item, and within them, in the middle (after the 5th post) will be added the ad.
I tested this extensively to ensure the current expectation.
If this is not working on your install it's either because of some compatibility issue (by disabling other software we would find out) or it's a specific setting you use and I asm not aware of.
Please ket me know the outcome, and if it's solved without other software.
If not, please send me your Views, exported from the Import/Export page of Toolset.
Beda is on vacation and this thread has only just been re-assigned to me, I'm sorry for the delay in getting back to you.
I tested this issue and it works with a simple unformatted Loop Output style, but doesn't with the Bootstrap grid style that you are using.
I tried several things to get it to work, such as changing the order of the index sections or hard-coding an index number such as 5 instead of using split2, but nothing was output in this case.
I've escalated this so that my colleagues can investigate further, I'll let you know when they have a fix.
In the meantime you could register a custom shortcode that checks the loop iteration and use that in a conditional check to show your advertising section after every, say, 6th post. (An even number because you are displaying posts in two columns.)
Here is the shortcode you would need to register:
/**
* Add loop-iteration shortcode
*
* Attributes
* 'n' (optional) : test for nth iteration
*/
add_shortcode( 'loop-iteration', function( $atts ){
global $loop_n;
if ( !isset( $loop_n ) ) {
$loop_n = 0;
return $loop_n;
}
$loop_n++;
if ( !isset( $atts['n'] ) ) {
// no nth parameter, just return the current index
return $loop_n;
}
else {
$remainder = ( $loop_n + 1 ) % $atts['n'];
return ( $remainder == 0 );
}
});
You then need to go to Toolset > Settings > Front-end Content and register this loop-iteration shortcode under "Third-party shortcode arguments".
Thanks Nigel. No rush, busy time of year for everyone.
Is it best to insert the code you provided or wait until the escalation is resolved? The site is still under development, so I don't mind waiting until an answer is provided and only changing the code once.