/home/bdqbpbxa/demo-subdomains/homesearch.goodface.com.ua/wp-content/themes/homesearch/blog.php
<?php
// Template name: Blog
get_header();
?>
<main>
<?php
get_template_part('templates/inner-page-main');
?>
<?php
$featured_articles_list = new WP_query([
'post_type' => 'post',
'post_per_page' => -1,
'meta_query' => [
[
'key' => 'preview_featured_article',
'value' => 1
],
]
]);
$featured_articles = get_field('featured_articles');
if ($featured_articles['title']) :
?>
<section class="related-article">
<div class="container -smaller">
<h2 class="title-2 mob-title-2 -centered-title -max-width-710"><?php echo $featured_articles['title']; ?></h2>
<div class="article-list -max-width-1120">
<?php
foreach($featured_articles_list->posts as $item) {
$args['post_id'] = $item->ID;
get_template_part('templates/cards/article-preview', null, $args);
}
?>
</div>
</div>
</section>
<?php
endif;
?>
<?php
$post_tabs = get_field('post_tabs');
$all_tab_title = $post_tabs['all_tab_title'];
$my_posts = new WP_Query([
'posts_per_page' => -1,
'post_type' => 'post',
'meta_query' => [
[
'key' => 'where-to-show',
'value' => "blog",
],
],
'orderby' => 'date',
'order' => 'DESC',
]);
?>
<section class="blog-section <?php echo get_section_color($post_tabs['block_color']); ?>">
<div class="container -smaller">
<div class="blog --tabs-container -max-width-1120" data-blog-type="blog" data-post-count="6">
<div class="blog__tabs-menu text-1 mob-text-2 --tabs-container__menu">
<div class="blog__tabs-menu-wrapper">
<div class="blog__tabs-menu-item --tabs-container__menu-item" data-cat-slug="null" data-cat-post-count="<?php echo count($my_posts->posts); ?>">
<span class="bold --demi-bold"> <?php echo $all_tab_title; ?> </span>
<span class="regular"> <?php echo $all_tab_title; ?> </span>
</div>
<?php
$categories = [];
foreach($my_posts->posts as $key=>$item) {
$category_obj = get_the_category($item->ID);
foreach($category_obj as $item) {
$element_exist = false;
if ($key != 0) {
foreach ($categories as $global_item) {
if (in_array($item->slug, $global_item)) {
$element_exist = true;
}
}
}
if (!$element_exist) {
$cat_posts = new WP_Query([
'posts_per_page' => -1,
'post_type' => 'post',
'category_name' => $item->slug,
'meta_query' => [
[
'key' => 'where-to-show',
'value' => "blog",
],
],
]);
$cat_arr = [
'cat_slug' => $item->slug,
'cat_name' => $item->name,
'cat_count' => count($cat_posts->posts),
];
array_push($categories, $cat_arr);
}
}
}
foreach($categories as $item) :
?>
<div class="blog__tabs-menu-item --tabs-container__menu-item" data-cat-slug="<?php echo $item['cat_slug']; ?>" data-cat-post-count="<?php echo $item['cat_count']; ?>">
<span class="bold --demi-bold"> <?php echo $item['cat_name']; ?> </span>
<span class="regular"> <?php echo $item['cat_name']; ?> </span>
</div>
<?php
endforeach;
?>
</div>
<div class="blog__tabs-menu-line --tabs-container__menu-line"></div>
</div>
<div class="blog__tabs-item --tabs-container__items">
<div class="--tabs-container__items-inner filter-result">
<div class="article-list">
<?php
$args['category'] = null;
$args['post_count'] = 6;
$args['blog_type'] = 'blog';
get_template_part('templates/blog-ajax-result', null, $args);
?>
</div>
</div>
<div class="article-load-more" data-check-in-viewport>
</div>
</div>
</div>
</div>
</section>
</main>
<?php
get_footer();
?>