这段代码把你的广告放在哪里。
<div>
<?php
global $post;
$terms = get_the_terms( $post->ID, \'post\' );
foreach ($terms as $term) {
$product_cat_id = $term->term_id;
break;
}
if($product_cat_id==\'18\'){
// your ads code put here for this categories
}else if($product_cat_id==\'19\'){
// your ads code put here for this categories
}
else{
// your default ads when categories not found then it display.
}
?>
</div>
MY Updated code :
function wpse_ad_content($content)
{global $post;
if (!is_single()) return $content;
if(!in_category(\'13\')) return $content;
$paragraphAfter = 2; //Enter number of paragraphs to display ad after.
$content = explode("</p>", $content);
$new_content = \'\';
for ($i = 0; $i < count($content); $i++) {
if ($i == $paragraphAfter) {
$new_content.= \'<div style="width: 300px; height: 250px; padding: 6px 6px 6px 0; float: left; margin-left: 0; margin-right: 18px;">\';
$terms = get_the_terms( $post->ID, \'category\' );
foreach ($terms as $term) {
$product_cat_id = $term->term_id;
break;
}
if($product_cat_id==\'13\'){
$new_content.= \'aaaaa\';
}else if($product_cat_id==\'19\'){
// your ads code put here for this categories
$new_content.= \'bbbb\';
}
else{
// your default ads when categories not found then it display.
$new_content.= \'cccc\';
}
$new_content.= \'</div>\';
}
$new_content.= $content[$i] . "</p>";
}
return $new_content;
}
注意:更改类别id。