Я пытаюсь вставить рекламу после каждого 3,6,9 конкретного тега, который я добавил в листинг, используя эту функцию: (Код отредактирован с получением контента)
add_filter( 'get_the_content', 'prefix_insert_post_ads2' );
function prefix_insert_post_ads2( $content ) {
//The last condition here ensures that ads are only added to posts
if ( is_archive()) {
return prefix_insert_ads( $content );
}
return $content;
}
function prefix_insert_ads( $content ) {
$closing_p = '</em>';
$paragraphs = explode( $closing_p, $content );
foreach ($paragraphs as $index => $paragraph) {
$paragraphs[$index] .= $closing_p;
if ( in_array($index, array(3, 6, 9)) ) {
//Replace the html here with a valid version of your ad code
$paragraphs[$index] .= '<div>Ad goes here</div>';
}
}
return implode( '', $paragraphs );
}
Но не работаетв листинге таксономии я пытался использовать if is archive, if is tax, if is archive, если имеет термин, даже если он разбит на страницы !, но не работает вообще.Но довольно странно работает в другом списке, который находится на странице.Является ли плагин wp Events Manager таксономией, может быть, мне нужно создать заполнитель ¿?, Я понятия не имею, почему не работает.Есть идеи?
ОБНОВЛЕНО:
Я использую эту функцию сейчас и тоже не работает:
//Insert ads
function prefix_insert_after_paragraph( $ads, $content ) {
if ( ! is_array( $ads ) ) {
return $content;
}
$closing_p = '</em>';
$paragraphs = explode( $closing_p, $content );
foreach ($paragraphs as $index => $paragraph) {
if ( trim( $paragraph ) ) {
$paragraphs[$index] .= $closing_p;
}
$n = $index + 1;
if ( isset( $ads[ $n ] ) ) {
$paragraphs[$index] .= $ads[ $n ];
}
}
return implode( '', $paragraphs );
}
add_filter( 'the_content', 'prefix_insert_ads' );
function prefix_insert_ads( $content ) {
if ( is_archive() && ! is_admin() ) {
$content = prefix_insert_after_paragraph( array(
'3' => '<div>1</div>',
'6' => '<div>2</div>',
'9' => '<div>3</div>',
), $content );
}
return $content;
}