Код был написан разработчиком, с которым мы не можем связаться. Это фрагмент кода 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;
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