Extension talk:S5h adsense filter

From mediawiki.org

I would like to achieve the following: If there are 2+ h2 headings on my page: Display the banner in front of the second one If there are no or just 1 h2 heading: Display the banner at the very end

I already got the banner in front of the headings:

$parts = explode( "<" . $para . ">", $text, $ads <= 0 ? 0 : $ads+1 );
$text = implode( $advert_block . "<" . $para . ">", $parts );

But I don't get the rest done...