hesabixWpTheme/template-parts/blog/archive-body.php

85 lines
4.3 KiB
PHP

<?php
/**
* بدنه مشترک آرشیو وبلاگ (لیست + جستجو + صفحه‌بندی)
*
* @package Hesabix2
*
* @var WP_Query $blog_query
* @var string $search
* @var bool $show_featured
*/
if (!defined('ABSPATH')) {
exit;
}
$blog_query = isset($blog_query) && $blog_query instanceof WP_Query ? $blog_query : $GLOBALS['wp_query'];
$search = isset($search) ? (string) $search : '';
$show_featured = !empty($show_featured) && !$search && (int) $blog_query->get('paged') < 2;
$form_action = hesabix2_blog_url();
$current_cat = hesabix2_blog_current_category_id();
?>
<div class="container mx-auto px-4 py-10 lg:py-12">
<div class="blog-archive-toolbar mb-8">
<form method="get" action="<?php echo esc_url($form_action); ?>" class="blog-search-form" role="search">
<div class="relative">
<label for="blog-search-input" class="sr-only"><?php esc_html_e('جستجو در وبلاگ', 'hesabix2'); ?></label>
<input type="search"
id="blog-search-input"
name="s"
value="<?php echo esc_attr($search); ?>"
placeholder="<?php esc_attr_e('جستجو در وبلاگ...', 'hesabix2'); ?>"
class="blog-search-input w-full px-4 py-3 pr-12 border border-slate-300 rounded-xl focus:ring-2 focus:ring-brand-500 focus:border-transparent transition-all duration-200 text-right bg-white">
<button type="submit" class="blog-search-btn absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-brand-600 transition-colors" aria-label="<?php esc_attr_e('جستجو', 'hesabix2'); ?>">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path>
</svg>
</button>
</div>
</form>
</div>
<?php hesabix2_render_blog_category_filters($current_cat); ?>
<?php if ($blog_query->have_posts()) : ?>
<?php if ($show_featured) : ?>
<?php
$blog_query->the_post();
get_template_part('template-parts/blog/featured');
$show_featured = false;
?>
<div class="blog-cards-grid grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 lg:gap-8 mb-12 mt-10">
<?php else : ?>
<div class="blog-cards-grid grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 lg:gap-8 mb-12">
<?php endif; ?>
<?php while ($blog_query->have_posts()) : $blog_query->the_post(); ?>
<?php get_template_part('template-parts/blog/card'); ?>
<?php endwhile; ?>
</div>
<?php hesabix2_render_blog_pagination($blog_query, $search); ?>
<?php else : ?>
<div class="blog-empty text-center py-16">
<div class="max-w-md mx-auto">
<svg class="w-16 h-16 text-slate-300 mx-auto mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path>
</svg>
<h3 class="text-xl font-semibold text-slate-900 mb-2"><?php esc_html_e('هیچ پستی یافت نشد', 'hesabix2'); ?></h3>
<p class="text-slate-600 mb-6">
<?php if ($search) : ?>
<?php printf(esc_html__('برای عبارت «%s» نتیجه‌ای یافت نشد.', 'hesabix2'), esc_html($search)); ?>
<?php else : ?>
<?php esc_html_e('هنوز مطلبی در این بخش منتشر نشده است.', 'hesabix2'); ?>
<?php endif; ?>
</p>
<a href="<?php echo esc_url(hesabix2_blog_url()); ?>" class="blog-empty-back inline-flex items-center gap-2 text-brand-600 font-medium hover:underline">
<?php esc_html_e('مشاهده همه مطالب', 'hesabix2'); ?>
</a>
</div>
</div>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
</div>