Using php insertBefore inside for loop -
i working on adding amp-ad amp pages based on how many paragraphs in post. trying figure out why loop adding 1 item when suppose adding item every 10 paragraphs. post working on has 100+ paragraphs. not live yet need figuring out why not adding item every 10. here code:
$p_nodes = $body->getelementsbytagname( 'p' ); if ( $p_nodes->length > 10 ) { for($i=10; $i <= $p_nodes->length; $i+=10) { $p_nodes->item( $i )->parentnode->insertbefore( $ad_node, $p_nodes->item( $i )); } }else{ $p_nodes->item( 10 )->parentnode->insertbefore( $ad_node, $p_nodes->item( 10 )); }
Comments
Post a Comment