Created
March 20, 2019 09:52
-
-
Save benlumley/2a299f5279ae7f3b235808946ce911e8 to your computer and use it in GitHub Desktop.
Add banners into content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(function ($) { | |
var $banners = $('aside .ba'); | |
if ($banners.length) { | |
// find all the headings in post body - we want to put the banners in after headers | |
var $headings = $('#post_full .span9 > *').filter(':header'); | |
// work out how often to put one in | |
var inc = Math.floor($headings.length / $banners.length); | |
var current = inc+1; | |
// loop over the banners, insert after headings using the above increment | |
$banners.each(function () { | |
$this = $(this); | |
jQuery($headings.get(current)).after($this); | |
current = current + inc; | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment