Встраивание рекламного текста в статью в разных точкахPhp

Кемеровские программисты php общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Встраивание рекламного текста в статью в разных точках

Сообщение Anonymous »

У нас есть рекламный текст (текст А), который мы хотим встроить в статью (текст Б) в определенных местах, например при 25% или 50% и т. д. Проблема в том, что после добавления текст A не отображается в тексте B.
Код был написан разработчиком, с которым мы не можем связаться. Это фрагмент кода WordPress на PHP.
Не уверен, имеет ли это объяснение смысл, не стесняйтесь задавать уточняющие вопросы.
Вот код, который у нас есть:
add_filter( 'the_content', 'move_custom_content_in_the_main_loop', 1 );
function move_custom_content_in_the_main_loop( $content ) {
// Продолжайте, только если это одна запись и основной запрос.// Примечание. Удалена проверка in_the_loop(), поскольку она может вести себя не так, как ожидалось, с Elementor.
if ( is_singular() && is_main_query() && get_the_ID() == 21197 ) {
// Получить значения полей ACF.
$acf_value = get_field( 'kies_promosie' );
$acf_value_2 = get_field( 'kies_promosie_2' );
$acf_value_3 = get_field( 'kies_promosie_3' );

Код: Выделить всё

    // Split the content into paragraphs.
$paragraphs = preg_split( '//', $content );
$total_paragraphs = count($paragraphs);
$insertions = 0;

// Ensure there are paragraphs to work with.
if ($total_paragraphs > 0) {
// Insertions for each ACF field if they have values.
if ( $acf_value ) {
$first_position = max(round(0.25 * $total_paragraphs) - 1 + $insertions, 0);
array_splice( $paragraphs, $first_position, 0, '
' . do_shortcode( '[elementor-template id="8471"]' ) . '
' );
$insertions++;
}

if ( $acf_value_2 ) {
$second_position = max(round(0.5 * $total_paragraphs) - 1 + $insertions, 0);
array_splice( $paragraphs, $second_position, 0, '
' . do_shortcode( '[elementor-template id="16315"]' ) . '
' );
$insertions++;
}

if ( $acf_value_3 ) {
$third_position = max(round(0.75 * $total_paragraphs) - 1 + $insertions, 0);
array_splice( $paragraphs, $third_position, 0, '
' . do_shortcode( '[elementor-template id="16316"]' ) . '
' );
}

// Reconstruct the content.
$content = implode( '', $paragraphs );
}
}

return $content;
add_filter( 'the_content', 'move_custom_content_in_the_main_loop', 1 );
function move_custom_content_in_the_main_loop( $content ) {
// Продолжайте, только если это один пост и основной запрос.
// Примечание. Удалена проверка in_the_loop(), поскольку она может вести себя не так, как ожидалось, с Elementor.
if ( is_singular() && is_main_query() && get_the_ID() == 21197 ) {
// Получить значения поля ACF.
$acf_value = get_field( 'kies_promosie' );
$acf_value_2 = get_field ( 'kies_promosie_2' );
$acf_value_3 = get_field( 'kies_promosie_3' );

Код: Выделить всё

    // Split the content into paragraphs.
$paragraphs = preg_split( '//', $content );
$total_paragraphs = count($paragraphs);
$insertions = 0;

// Ensure there are paragraphs to work with.
if ($total_paragraphs > 0) {
// Insertions for each ACF field if they have values.
if ( $acf_value ) {
$first_position = max(round(0.25 * $total_paragraphs) - 1 + $insertions, 0);
array_splice( $paragraphs, $first_position, 0, '
' . do_shortcode( '[elementor-template id="8471"]' ) . '
' );
$insertions++;
}

if ( $acf_value_2 ) {
$second_position = max(round(0.5 * $total_paragraphs) - 1 + $insertions, 0);
array_splice( $paragraphs, $second_position, 0, '
' . do_shortcode( '[elementor-template id="16315"]' ) . '
' );
$insertions++;
}

if ( $acf_value_3 ) {
$third_position = max(round(0.75 * $total_paragraphs) - 1 + $insertions, 0);
array_splice( $paragraphs, $third_position, 0, '
' . do_shortcode( '[elementor-template id="16316"]' ) . '
' );
}

// Reconstruct the content.
$content = implode( '', $paragraphs );
}
}

return $content;


Подробнее здесь: https://stackoverflow.com/questions/784 ... ent-points
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Php»