207 lines
12 KiB
PHP
207 lines
12 KiB
PHP
<?php
|
|
/**
|
|
* لیست سوالات — طرح hesabix2
|
|
*
|
|
* @package Hesabix2
|
|
* @subpackage AnsPress
|
|
*/
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
$popular_tags = get_terms(
|
|
array(
|
|
'taxonomy' => 'question_tag',
|
|
'orderby' => 'count',
|
|
'order' => 'DESC',
|
|
'number' => 20,
|
|
'hide_empty' => false,
|
|
)
|
|
);
|
|
|
|
global $question_tag, $wp_query;
|
|
if ( ! isset( $question_tag ) && is_tax( 'question_tag' ) ) {
|
|
$question_tag = get_queried_object();
|
|
}
|
|
|
|
$hesabix2_ap_filters_action = ap_get_link_to( '/' );
|
|
if ( function_exists( 'is_tax' ) ) {
|
|
if ( is_tax( 'question_tag' ) || is_tax( 'question_category' ) ) {
|
|
$term_link = get_term_link( get_queried_object() );
|
|
if ( ! is_wp_error( $term_link ) ) {
|
|
$hesabix2_ap_filters_action = $term_link;
|
|
}
|
|
}
|
|
}
|
|
|
|
$total_questions = isset( $wp_query->found_posts ) ? $wp_query->found_posts : 0;
|
|
if ( ! $total_questions && isset( anspress()->questions->total_count ) ) {
|
|
$total_questions = anspress()->questions->total_count;
|
|
}
|
|
|
|
$question_tag_term_count = wp_count_terms(
|
|
array(
|
|
'taxonomy' => 'question_tag',
|
|
'hide_empty' => false,
|
|
)
|
|
);
|
|
if ( is_wp_error( $question_tag_term_count ) ) {
|
|
$question_tag_term_count = 0;
|
|
}
|
|
?>
|
|
|
|
<div class="ap-question-list hesabix2-ap-list">
|
|
<!-- هدر پرسش و پاسخ -->
|
|
<section class="ap-list-hero ap-hero-qa rounded-2xl mb-5 sm:mb-6 overflow-hidden">
|
|
<div class="relative z-10 px-4 sm:px-5 py-5 sm:py-6 lg:py-7">
|
|
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-6">
|
|
<div>
|
|
<span class="ap-hero-badge">
|
|
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
|
|
<?php esc_html_e( 'انجمن پرسش و پاسخ', 'anspress-question-answer' ); ?>
|
|
</span>
|
|
<h1 class="text-2xl sm:text-3xl lg:text-4xl font-extrabold text-slate-800 mb-2 tracking-tight">
|
|
<?php
|
|
if ( isset( $question_tag ) && ! empty( $question_tag->name ) ) {
|
|
echo esc_html( 'پرسش و پاسخ — ' . $question_tag->name );
|
|
} else {
|
|
esc_html_e( 'پرسش و پاسخ', 'anspress-question-answer' );
|
|
}
|
|
?>
|
|
</h1>
|
|
<p class="text-slate-600 text-base sm:text-lg max-w-xl">
|
|
<?php esc_html_e( 'سوالات خود را بپرسید و از تجربه دیگران استفاده کنید', 'anspress-question-answer' ); ?>
|
|
</p>
|
|
</div>
|
|
<div class="flex-shrink-0">
|
|
<?php if ( ap_user_can_ask() ) : ?>
|
|
<a href="<?php echo esc_url( ap_get_link_to( 'ask' ) ); ?>" class="inline-flex items-center gap-2 bg-brand-500 hover:bg-brand-600 text-white px-6 py-3.5 rounded-xl font-semibold shadow-lg shadow-brand-500/25 hover:shadow-xl hover:shadow-brand-500/20 transition-all duration-200">
|
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg>
|
|
<span><?php esc_html_e( 'سوال جدید', 'anspress-question-answer' ); ?></span>
|
|
</a>
|
|
<?php else : ?>
|
|
<a href="<?php echo esc_url( wp_login_url( ap_get_link_to( 'ask' ) ) ); ?>" class="inline-flex items-center gap-2 bg-brand-500 hover:bg-brand-600 text-white px-6 py-3.5 rounded-xl font-semibold shadow-lg shadow-brand-500/25 transition-all duration-200">
|
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path d="M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4"></path><polyline points="10,17 15,12 10,7"></polyline><line x1="15" y1="12" x2="3" y2="12"></line></svg>
|
|
<span><?php esc_html_e( 'ورود برای پرسیدن سوال', 'anspress-question-answer' ); ?></span>
|
|
</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<div class="flex flex-col lg:flex-row gap-5 sm:gap-6">
|
|
<div class="flex-1 min-w-0">
|
|
<!-- فیلتر و جستجو -->
|
|
<?php if ( ! get_query_var( 'ap_hide_list_head' ) ) : ?>
|
|
<div class="ap-filters-card ap-filters-bar rounded-2xl p-4 sm:p-5 mb-5">
|
|
<form method="GET" action="<?php echo esc_url( $hesabix2_ap_filters_action ); ?>" class="flex flex-col sm:flex-row gap-4 flex-wrap">
|
|
<div class="flex-1 min-w-[200px]">
|
|
<label for="ap-s" class="block text-sm font-medium text-slate-700 mb-1.5"><?php esc_html_e( 'جستجو', 'anspress-question-answer' ); ?></label>
|
|
<input type="text" name="ap_s" id="ap-s" value="<?php echo esc_attr( get_query_var( 'ap_s' ) ); ?>" placeholder="<?php esc_attr_e( 'جستجو در سوالات...', 'anspress-question-answer' ); ?>" class="w-full px-4 py-2.5 bg-white border border-slate-200 rounded-xl focus:ring-2 focus:ring-brand-500 focus:border-brand-400 text-slate-800 placeholder-slate-400 transition-shadow">
|
|
</div>
|
|
<div class="w-full sm:w-52">
|
|
<label for="ap-order" class="block text-sm font-medium text-slate-700 mb-1.5"><?php esc_html_e( 'مرتبسازی', 'anspress-question-answer' ); ?></label>
|
|
<select name="ap_order_by" id="ap-order" class="w-full px-4 py-2.5 bg-white border border-slate-200 rounded-xl focus:ring-2 focus:ring-brand-500 text-slate-700">
|
|
<option value="active" <?php selected( ap_get_current_list_filters( 'order_by' ), 'active' ); ?>><?php esc_html_e( 'فعال', 'anspress-question-answer' ); ?></option>
|
|
<option value="newest" <?php selected( ap_get_current_list_filters( 'order_by' ), 'newest' ); ?>><?php esc_html_e( 'جدیدترین', 'anspress-question-answer' ); ?></option>
|
|
<option value="voted" <?php selected( ap_get_current_list_filters( 'order_by' ), 'voted' ); ?>><?php esc_html_e( 'محبوبترین', 'anspress-question-answer' ); ?></option>
|
|
<option value="unanswered" <?php selected( ap_get_current_list_filters( 'order_by' ), 'unanswered' ); ?>><?php esc_html_e( 'بدون پاسخ', 'anspress-question-answer' ); ?></option>
|
|
<option value="solved" <?php selected( ap_get_current_list_filters( 'order_by' ), 'solved' ); ?>><?php esc_html_e( 'حل شده', 'anspress-question-answer' ); ?></option>
|
|
</select>
|
|
</div>
|
|
<div class="flex items-end">
|
|
<button type="submit" class="bg-brand-500 hover:bg-brand-600 text-white px-6 py-2.5 rounded-xl font-semibold inline-flex items-center gap-2 shadow-md hover:shadow-lg transition-all">
|
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"></circle><path d="m21 21-4.35-4.35"></path></svg>
|
|
<span><?php esc_html_e( 'جستجو', 'anspress-question-answer' ); ?></span>
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<!-- لیست سوالات -->
|
|
<?php if ( ap_have_questions() ) : ?>
|
|
<div class="ap-questions-grid space-y-4">
|
|
<?php
|
|
while ( ap_have_questions() ) :
|
|
ap_the_question();
|
|
ap_get_template_part( 'question-list-item' );
|
|
endwhile;
|
|
?>
|
|
</div>
|
|
|
|
<?php
|
|
$hesabix2_ap_max_pages = isset( anspress()->questions->max_num_pages ) ? (int) anspress()->questions->max_num_pages : 1;
|
|
if ( $hesabix2_ap_max_pages > 1 && function_exists( 'ap_questions_the_pagination' ) ) :
|
|
?>
|
|
<div class="hesabix2-ap-pagination-wrap mt-6 pt-6 border-t border-slate-200" role="navigation" aria-label="<?php esc_attr_e( 'صفحهبندی', 'anspress-question-answer' ); ?>">
|
|
<?php ap_questions_the_pagination(); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php else : ?>
|
|
<div class="ap-empty bg-white rounded-2xl shadow-sm border border-slate-100 p-8 sm:p-10 text-center">
|
|
<div class="ap-empty-illustration inline-flex items-center justify-center w-20 h-20 rounded-2xl bg-light-50 border border-slate-100 mb-6">
|
|
<svg class="w-10 h-10 text-brand-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
|
|
</div>
|
|
<h3 class="text-xl font-bold text-slate-800 mb-2"><?php esc_html_e( 'سوالی یافت نشد', 'anspress-question-answer' ); ?></h3>
|
|
<p class="text-slate-600 mb-6 max-w-sm mx-auto"><?php esc_html_e( 'هنوز سوالی در این دستهبندی وجود ندارد.', 'anspress-question-answer' ); ?></p>
|
|
<?php if ( ap_user_can_ask() ) : ?>
|
|
<a href="<?php echo esc_url( ap_get_link_to( 'ask' ) ); ?>" class="inline-flex items-center gap-2 bg-brand-500 hover:bg-brand-600 text-white px-6 py-3.5 rounded-xl font-semibold shadow-md hover:shadow-lg transition-all">
|
|
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><line x1="12" y1="5" x2="12" y2="19"></line><line x1="5" y1="12" x2="19" y2="12"></line></svg>
|
|
<span><?php esc_html_e( 'اولین سوال را بپرسید', 'anspress-question-answer' ); ?></span>
|
|
</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<!-- سایدبار -->
|
|
<aside class="lg:w-72 flex-shrink-0 space-y-4">
|
|
<?php if ( ! is_wp_error( $popular_tags ) && ! empty( $popular_tags ) ) : ?>
|
|
<div class="ap-sidebar-card ap-sidebar-card-qa bg-white rounded-2xl shadow-sm p-4 sm:p-5">
|
|
<h3 class="text-lg font-bold text-slate-800 mb-4 flex items-center gap-2">
|
|
<span class="flex items-center justify-center w-8 h-8 rounded-lg bg-brand-500/10 text-brand-600">
|
|
<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="M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z"></path></svg>
|
|
</span>
|
|
<?php esc_html_e( 'تگهای محبوب', 'anspress-question-answer' ); ?>
|
|
</h3>
|
|
<div class="flex flex-wrap gap-2">
|
|
<?php foreach ( $popular_tags as $tag ) : ?>
|
|
<a href="<?php echo esc_url( get_term_link( $tag ) ); ?>" class="ap-tag inline-flex items-center px-3 py-1.5 bg-light-100 text-brand-600 rounded-full text-sm font-medium hover:bg-brand-500/10 hover:text-brand-700 transition-colors">
|
|
<?php echo esc_html( $tag->name ); ?>
|
|
<span class="text-slate-500 ms-1 text-xs">(<?php echo (int) $tag->count; ?>)</span>
|
|
</a>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php if ( function_exists( 'ap_get_link_to' ) ) : ?>
|
|
<a href="<?php echo esc_url( ap_get_link_to( 'tags' ) ); ?>" class="mt-4 inline-flex items-center gap-1 text-brand-600 hover:text-brand-700 font-medium text-sm transition-colors">
|
|
<span><?php esc_html_e( 'مشاهده همه تگها', 'anspress-question-answer' ); ?></span>
|
|
<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 19l-7-7 7-7"></path></svg>
|
|
</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="ap-stats-card ap-sidebar-card-qa bg-white rounded-2xl p-4 sm:p-5 shadow-sm">
|
|
<h3 class="text-lg font-bold text-slate-800 mb-4 flex items-center gap-2">
|
|
<span class="flex items-center justify-center w-8 h-8 rounded-lg bg-success-500/10 text-success-500">
|
|
<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="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"></path></svg>
|
|
</span>
|
|
<?php esc_html_e( 'آمار', 'anspress-question-answer' ); ?>
|
|
</h3>
|
|
<div class="grid grid-cols-2 gap-4 text-center">
|
|
<div class="ap-stats-num p-3 rounded-xl bg-light-50 border border-slate-100">
|
|
<div class="text-2xl font-bold text-brand-600"><?php echo esc_html( number_format_i18n( $total_questions ) ); ?></div>
|
|
<div class="text-sm text-slate-600"><?php esc_html_e( 'سوال', 'anspress-question-answer' ); ?></div>
|
|
</div>
|
|
<div class="ap-stats-num p-3 rounded-xl bg-light-50 border border-slate-100">
|
|
<div class="text-2xl font-bold text-success-500"><?php echo esc_html( number_format_i18n( $question_tag_term_count ) ); ?></div>
|
|
<div class="text-sm text-slate-600"><?php esc_html_e( 'كل تگها', 'anspress-question-answer' ); ?></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</aside>
|
|
</div>
|
|
</div>
|