function register_promo_type() {
register_post_type('promo', array(
'labels' => array(
'name' => 'Промо',
'singular_name' => 'Промо',
),
'public' => true,
'supports' => array('title'),
'has_archive' => false,
'menu_icon' => 'dashicons-megaphone',
));
}
add_action('init', 'register_promo_post_type');
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array(
'key' => 'group_promo',
'title' => 'Настройки',
'fields' => array(
array(
'key' => 'field_promo_taxonomy_id',
'label' => 'ID Таксономии',
'name' => 'promo_taxonomy_id',
'type' => 'text',
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => 'promo',
),
),
),
));
function display_promo_after_content($content) {
if (is_singular('post')) {
$current_post = get_queried_object();
$taxonomy_id = get_field('promo_taxonomy_id');
if (has_term(88, 'category', $current_post)) {
$args = array(
'post_type' => 'promo,
'posts_per_page' => -1,
);
$promo_blocks = new WP_Query($args);
if ($promo_blocks->have_posts()) {
while ($promo_blocks->have_posts()) {
$promo_blocks->the_post();
$title = get_field('promo_title');
$subtitle = get_field('promo_subtitle');
$button_text = get_field('promo_button_text');
$button_link = get_field('promo_button_link');
$title_color = get_field('promo_title_color');
$subtitle_color = get_field('promo_subtitle_color');
$button_bg_color = get_field('promo_button_bg_color');
$bg_color = get_field('promo_bg_color');
$border_color = get_field('promo_border_color');
$promo_html = '<div class="container" style="background-color: ' . esc_attr($bg_color) . '; border: 1px solid ' . esc_attr($border_color) . ';">';
$promo_html .= '<div class="column">';
$promo_html .= '<h2 style="color: ' . esc_attr($title_color) . ';">' . esc_html($title) . '</h2>';
if (!empty($subtitle)) {
$promo_html .= '<p style="color: ' . esc_attr($subtitle_color) . ';">' . esc_html($subtitle) . '</p>';
}
$promo_html .= '</div>';
$promo_html .= '<div class="column">';
if (!empty($button_text) && !empty($button_link)) {
$promo_html .= '<a href="' . esc_url($button_link) . '" class="btn" style="background-color: ' . esc_attr($button_bg_color) . ';">' . esc_html($button_text) . '</a>';
}
$promo_html .= '</div>';
$promo_html .= '</div>';
$content .= $promo_html;
}
wp_reset_postdata();
}
}
}
return $content;
}
add_filter('the_content', 'display_blocks_after_content');