hesabixWpTheme/home.php
2026-05-22 13:52:15 +03:30

206 lines
13 KiB
PHP

<?php
/**
* قالب لیست مطالب وبلاگ
* با الهام از قالب Hesabix
*
* @package Hesabix2
*/
get_header();
$blog_page_id = get_option('page_for_posts');
$blog_url = $blog_page_id ? get_permalink($blog_page_id) : home_url('/blog');
$search = isset($_GET['s']) ? sanitize_text_field(wp_unslash($_GET['s'])) : '';
$paged = get_query_var('paged') ? absint(get_query_var('paged')) : 1;
$args = array(
'post_type' => 'post',
'posts_per_page' => 9,
'paged' => $paged,
'orderby' => 'date',
'order' => 'DESC',
'post_status' => 'publish',
);
if ($search) {
$args['s'] = $search;
}
$blog_query = new WP_Query($args);
$max_pages = $blog_query->max_num_pages;
$form_action = $blog_page_id ? get_permalink($blog_page_id) : home_url('/');
$layout_class = hesabix2_has_sidebar() ? 'layout-wrap layout--with-sidebar' : 'layout-wrap layout--single';
?>
<div class="<?php echo esc_attr($layout_class); ?>">
<main class="blog-archive layout-main min-h-screen bg-slate-50">
<!-- هدر وبلاگ -->
<div class="relative bg-gradient-to-br from-brand-500 via-violet-500 to-brand-600 overflow-hidden">
<div class="absolute inset-0 bg-black/30"></div>
<div class="relative container mx-auto px-4 py-16 lg:py-20">
<div class="text-center text-white">
<h1 class="blog-hero-title text-3xl lg:text-5xl font-bold mb-4">وبلاگ حسابیکس</h1>
<p class="blog-hero-desc text-lg text-white/90 max-w-2xl mx-auto">جدیدترین اطلاعات و خبرها از دنیای حسابداری</p>
</div>
</div>
</div>
<!-- محتوای اصلی -->
<div class="container mx-auto px-4 py-10 lg:py-12">
<!-- جستجو -->
<div class="mb-8">
<form method="GET" action="<?php echo esc_url($form_action); ?>" class="max-w-md mx-auto">
<div class="relative">
<input type="text"
name="s"
value="<?php echo esc_attr($search); ?>"
placeholder="جستجو در وبلاگ..."
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">
<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 if ($blog_query->have_posts()) : ?>
<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 while ($blog_query->have_posts()) : $blog_query->the_post(); ?>
<?php
$categories = get_the_category();
$reading_time = hesabix2_reading_time(get_the_content());
$post_views = get_post_meta(get_the_ID(), 'post_views_count', true) ?: '0';
?>
<article id="post-<?php the_ID(); ?>" <?php post_class('blog-card group relative'); ?>>
<div class="blog-card-glow absolute inset-0 rounded-3xl blur opacity-20 group-hover:opacity-30 transition-opacity duration-300" aria-hidden="true"></div>
<div class="blog-card-inner relative bg-white rounded-3xl overflow-hidden shadow-lg hover:shadow-xl transition-all duration-300 min-h-[420px] max-h-[420px] flex flex-col">
<div class="relative overflow-hidden">
<?php if (has_post_thumbnail()) : ?>
<a href="<?php the_permalink(); ?>" class="block">
<?php the_post_thumbnail('large', array('class' => 'blog-card-img w-full h-48 object-cover group-hover:scale-105 transition-transform duration-500')); ?>
</a>
<?php else : ?>
<a href="<?php the_permalink(); ?>" class="block w-full h-48 bg-gradient-to-br from-slate-100 to-slate-200 flex items-center justify-center">
<svg class="w-16 h-16 text-slate-300" 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>
</a>
<?php endif; ?>
<?php if (!empty($categories)) : ?>
<div class="absolute top-4 right-4 flex flex-wrap gap-2">
<?php foreach (array_slice($categories, 0, 2) as $category) : ?>
<span class="blog-card-cat px-3 py-1 bg-brand-600 text-white text-xs font-medium rounded-full shadow">
<?php echo esc_html($category->name); ?>
</span>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<div class="p-5 lg:p-6 flex flex-col flex-1">
<div class="flex-1">
<div class="blog-card-meta flex items-center justify-between text-sm text-slate-500 mb-3">
<span class="flex items-center gap-1.5">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"></path></svg>
<time datetime="<?php echo esc_attr(get_the_date('c')); ?>"><?php echo esc_html(get_the_date('Y/n/d')); ?></time>
</span>
<span class="flex items-center gap-1.5">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"></path></svg>
<?php echo esc_html($post_views); ?> بازدید
</span>
</div>
<h2 class="blog-card-title text-lg font-bold text-slate-900 mb-2 line-clamp-2 group-hover:text-brand-600 transition-colors">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h2>
<p class="blog-card-excerpt text-slate-600 text-sm leading-relaxed line-clamp-3 mb-4">
<?php
$excerpt = get_the_excerpt();
echo $excerpt ? wp_trim_words($excerpt, 20) : wp_trim_words(get_the_content(), 20);
?>
</p>
</div>
<a href="<?php the_permalink(); ?>" class="blog-card-more inline-flex items-center gap-2 text-brand-600 hover:text-brand-700 font-medium text-sm transition-colors group/link">
<span>ادامه مطلب</span>
<svg class="w-4 h-4 group-hover/link:translate-x-0.5 transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path>
</svg>
</a>
</div>
</div>
</article>
<?php endwhile; ?>
</div>
<?php if ($max_pages > 1) : ?>
<nav class="blog-pagination flex justify-center" aria-label="صفحه‌بندی">
<div class="flex items-center gap-2 flex-wrap justify-center">
<?php
$big = 999999999;
$pagination_base = str_replace($big, '%#%', esc_url(get_pagenum_link($big)));
$pagination_args = array(
'base' => $pagination_base,
'format' => '?paged=%#%',
'current' => max(1, $paged),
'total' => $max_pages,
'prev_text' => '← قبلی',
'next_text' => 'بعدی →',
'type' => 'list',
'end_size' => 2,
'mid_size' => 1,
);
if ($search) {
$pagination_args['add_args'] = array('s' => urlencode($search));
}
$links = paginate_links($pagination_args);
if ($links) {
$links = str_replace('<ul class=\'page-numbers\'>', '<div class="flex items-center gap-1">', $links);
$links = str_replace('</ul>', '</div>', $links);
$links = str_replace('<li>', '', $links);
$links = str_replace('</li>', '', $links);
$links = str_replace('class="page-numbers"', 'class="blog-pagination-num px-4 py-2 text-sm font-medium text-slate-600 bg-white border border-slate-300 rounded-lg hover:bg-slate-50 hover:text-slate-800 transition-colors"', $links);
$links = str_replace('class="page-numbers current"', 'class="blog-pagination-num blog-pagination-num--current px-4 py-2 text-sm font-medium text-white bg-brand-600 border border-brand-600 rounded-lg"', $links);
$links = str_replace('class="prev page-numbers"', 'class="blog-pagination-num blog-pagination-prev px-4 py-2 text-sm font-medium text-slate-600 bg-white border border-slate-300 rounded-lg hover:bg-slate-50"', $links);
$links = str_replace('class="next page-numbers"', 'class="blog-pagination-num blog-pagination-next px-4 py-2 text-sm font-medium text-slate-600 bg-white border border-slate-300 rounded-lg hover:bg-slate-50"', $links);
echo $links;
}
?>
</div>
</nav>
<?php endif; ?>
<?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">
<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">هیچ پستی یافت نشد</h3>
<p class="text-slate-600 mb-6">
<?php if ($search) : ?>
برای عبارت «<?php echo esc_html($search); ?>» هیچ نتیجه‌ای یافت نشد.
<?php else : ?>
هنوز هیچ پستی منتشر نشده است.
<?php endif; ?>
</p>
<a href="<?php echo esc_url(home_url('/')); ?>" class="blog-empty-back inline-flex items-center gap-2 text-brand-600 font-medium hover:underline">بازگشت به صفحه نخست</a>
</div>
</div>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
</div>
</main>
<?php if (hesabix2_has_sidebar()) : ?>
<aside class="layout-sidebar" role="complementary">
<?php dynamic_sidebar('sidebar-1'); ?>
</aside>
<?php endif; ?>
</div>
<?php
get_footer();