136 lines
6.3 KiB
PHP
136 lines
6.3 KiB
PHP
<?php
|
|
/**
|
|
* نتایج جستجو
|
|
*
|
|
* @package Hesabix2
|
|
*/
|
|
|
|
get_header();
|
|
|
|
$query = get_search_query();
|
|
$paged = max(1, (int) get_query_var('paged'));
|
|
$layout = function_exists('hesabix2_blog_layout_class') ? hesabix2_blog_layout_class() : 'layout-wrap layout--single blog-layout--full';
|
|
|
|
global $wp_query;
|
|
$only_posts = true;
|
|
if ($wp_query->have_posts()) {
|
|
foreach ($wp_query->posts as $p) {
|
|
if ('post' !== $p->post_type) {
|
|
$only_posts = false;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
|
|
<div class="<?php echo esc_attr($layout); ?>">
|
|
<main id="main-content" class="search-results layout-main min-h-screen bg-slate-50">
|
|
<div class="bg-white border-b border-slate-200">
|
|
<div class="container mx-auto px-4 py-8">
|
|
<div class="w-full">
|
|
<?php if (function_exists('hesabix2_seo_render_breadcrumb')) {
|
|
hesabix2_seo_render_breadcrumb('hesabix2-breadcrumb');
|
|
} ?>
|
|
<h1 class="text-2xl sm:text-3xl font-bold text-slate-900 mb-2">
|
|
<?php
|
|
if ($query) {
|
|
printf(
|
|
esc_html__('نتایج جستجو برای «%s»', 'hesabix2'),
|
|
esc_html($query)
|
|
);
|
|
} else {
|
|
esc_html_e('جستجو در سایت', 'hesabix2');
|
|
}
|
|
?>
|
|
</h1>
|
|
<p class="text-slate-600 text-sm mb-6">
|
|
<?php
|
|
printf(
|
|
esc_html(_n('%s نتیجه', '%s نتیجه', (int) $wp_query->found_posts, 'hesabix2')),
|
|
esc_html(number_format_i18n((int) $wp_query->found_posts))
|
|
);
|
|
?>
|
|
</p>
|
|
<?php get_search_form(); ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="container mx-auto px-4 py-10 lg:py-12">
|
|
<?php if (have_posts()) : ?>
|
|
<?php if ($only_posts) : ?>
|
|
<div class="blog-cards-grid grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 lg:gap-8">
|
|
<?php while (have_posts()) : the_post(); ?>
|
|
<?php get_template_part('template-parts/blog/card'); ?>
|
|
<?php endwhile; ?>
|
|
</div>
|
|
<?php hesabix2_render_blog_pagination($wp_query, $query); ?>
|
|
<?php else : ?>
|
|
<ul class="search-results__list space-y-6 max-w-3xl mx-auto list-none m-0 p-0">
|
|
<?php while (have_posts()) : the_post(); ?>
|
|
<li>
|
|
<article <?php post_class('search-results__item bg-white rounded-2xl border border-slate-100 p-6 shadow-sm hover:shadow-md transition'); ?>>
|
|
<h2 class="text-lg font-bold text-slate-900 mb-2">
|
|
<a href="<?php the_permalink(); ?>" class="hover:text-brand-600 transition-colors"><?php the_title(); ?></a>
|
|
</h2>
|
|
<p class="text-xs text-slate-500 mb-3">
|
|
<span><?php echo esc_html(get_post_type_object(get_post_type())->labels->singular_name ?? get_post_type()); ?></span>
|
|
<?php if ('post' === get_post_type()) : ?>
|
|
· <time datetime="<?php echo esc_attr(get_the_date('c')); ?>"><?php echo esc_html(get_the_date()); ?></time>
|
|
<?php endif; ?>
|
|
</p>
|
|
<p class="text-slate-600 text-sm leading-relaxed line-clamp-3"><?php echo esc_html(wp_trim_words(get_the_excerpt(), 28)); ?></p>
|
|
<a href="<?php the_permalink(); ?>" class="inline-flex items-center gap-1 text-brand-600 text-sm font-medium mt-4 hover:text-brand-700">
|
|
<?php esc_html_e('مشاهده', 'hesabix2'); ?>
|
|
<span aria-hidden="true">←</span>
|
|
</a>
|
|
</article>
|
|
</li>
|
|
<?php endwhile; ?>
|
|
</ul>
|
|
<?php if ($wp_query->max_num_pages > 1) : ?>
|
|
<nav class="search-results__pagination mt-10 flex justify-center" aria-label="<?php esc_attr_e('صفحهبندی نتایج', 'hesabix2'); ?>">
|
|
<?php
|
|
echo paginate_links(array(
|
|
'current' => $paged,
|
|
'total' => $wp_query->max_num_pages,
|
|
'prev_text' => '← ' . __('قبلی', 'hesabix2'),
|
|
'next_text' => __('بعدی', 'hesabix2') . ' →',
|
|
'type' => 'list',
|
|
));
|
|
?>
|
|
</nav>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
<?php else : ?>
|
|
<div class="text-center py-16 bg-white rounded-2xl border border-slate-100 max-w-md mx-auto">
|
|
<h2 class="text-xl font-semibold text-slate-900 mb-2"><?php esc_html_e('نتیجهای یافت نشد', 'hesabix2'); ?></h2>
|
|
<p class="text-slate-600 mb-6">
|
|
<?php
|
|
if ($query) {
|
|
printf(
|
|
esc_html__('برای «%s» مطلبی پیدا نشد. عبارت دیگری امتحان کنید.', 'hesabix2'),
|
|
esc_html($query)
|
|
);
|
|
} else {
|
|
esc_html_e('عبارت جستجو را وارد کنید.', 'hesabix2');
|
|
}
|
|
?>
|
|
</p>
|
|
<a href="<?php echo esc_url(home_url('/')); ?>" class="inline-flex items-center gap-2 text-brand-600 font-medium hover:underline">
|
|
<?php esc_html_e('بازگشت به صفحه اصلی', 'hesabix2'); ?>
|
|
</a>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</main>
|
|
|
|
<?php if (hesabix2_show_layout_sidebar()) : ?>
|
|
<aside class="layout-sidebar" role="complementary">
|
|
<?php dynamic_sidebar('sidebar-1'); ?>
|
|
</aside>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<?php
|
|
get_footer();
|