Skip to content

Instantly share code, notes, and snippets.

@rxnlabs
Created September 28, 2015 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rxnlabs/3b461a6aa3bf69c2934f to your computer and use it in GitHub Desktop.
Save rxnlabs/3b461a6aa3bf69c2934f to your computer and use it in GitHub Desktop.
insert ad after paragraph
public function slipstream_ad_content($content)
{
if(!is_single() || get_post_type() == 'lp' || get_post_type() == 'got')
return $content;
global $agora_core, $dr_theme, $afp_openx;
$openx_script = (is_object($afp_openx)) ? $afp_openx->openx_script(array('zoneid' => $dr_theme->openx_635x120_zoneid)) : '';
$paragraphs = str_replace('</p>', '', $content);
// remove empty array elements and break apart the p tags
$paragraphs = array_filter(explode('<p>', $paragraphs));
$count = count( $paragraphs );
$where = floor( $count / 2 ) - 1;
// if there are two or less paragraphs
if( $count <= 2 ){
$where = 1;
}
$new_content = '';
foreach($paragraphs as $pnumber => $paragraph)
{
$new_content .= '<p>'.$paragraph.'</p>';
if($pnumber == $where) {
if(is_object($agora_core))
{
$new_content .= '<div id="in-flow-ad">' . $openx_script . '</div>';
}
}
}
return $new_content;
}
public function slipstream_ad_content( $content ){
global $agora_core;
$paragraphs = preg_split( "/[\n]+/", $content );
$count = count( $paragraphs );
$where = floor( $count / 2 ) - 1;
$new_content = '';
foreach( $paragraphs as $pnumber => $paragraph )
{
$new_content .= $paragraph;
if( $pnumber == $where ) {
if( is_object( $agora_core ) )
{
$new_content .= '<div id="in-flow-ad">' . $this->openx( $this->openx_635x120_single_interstitial_zoneid ) . '</div>';
}
}
}
return $new_content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment