Created
September 28, 2015 18:50
-
-
Save rxnlabs/3b461a6aa3bf69c2934f to your computer and use it in GitHub Desktop.
insert ad after paragraph
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
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; | |
} |
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
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