Я пытаюсь добавить adsense и связанные посты после x параграфов ; код работает, но не работает должным образом; Вверху появляется функция post thid, чтобы войти После количества абзацев и связанных с ним сообщений
add_filter('the_content', 'wpse_ad_content');
function wpse_ad_content($content)
{
if (!is_single()) return $content;
$paragraphAfter_1 = 2; //Enter number of paragraphs to display ad after.
$paragraphAfter_2 = 5; //Enter number of paragraphs to display ad after.
$content = explode("</p>", $content);
$new_content = '';
for ($i = 0; $i < count($content); $i++) {
if ($i == $paragraphAfter_1) {
$new_content.= '<h1>code ads here</h1>';}
if ($i == $paragraphAfter_2) {
***//show related posts after number of paragraphs***
global $post;
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$args=array(
'tag__in' => $tag_ids,
'post__not_in' => array($post->ID),
'posts_per_page'=>2, // Number of related posts to display.
'caller_get_posts'=>1
);
$my_query = new wp_query( $args );
while( $my_query->have_posts() ) {
$my_query->the_post();
echo'<a href="'.get_permalink().'">'.get_the_title().'</a><br />';
}
}
$post = $orig_post;
//wp_reset_query();
$new_content.= $post ;
***//show related posts after number of paragraphs***
}
$new_content.= $content[$i] . "</p>";
}
return $new_content;
}
/** ads **/
есть предложения? спасибо