hesabixWpTheme/single.php

280 lines
19 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* قالب نمایش یک پست وبلاگ
*
* @package Hesabix2
*/
get_header();
$layout_class = hesabix2_blog_layout_class();
?>
<div class="<?php echo esc_attr($layout_class); ?>">
<?php while (have_posts()) : the_post(); ?>
<?php
$plain = get_post_meta(get_the_ID(), 'plain', true);
if ($plain) :
echo '<main id="main-content" class="single-post-page layout-main"><div class="page-plain-content container mx-auto px-4 py-12">';
echo wp_kses_post($plain);
echo '</div></main>';
else :
$post_id = get_the_ID();
$post_title = get_the_title();
$post_author = get_the_author();
$author_url = get_author_posts_url((int) get_the_author_meta('ID'));
$post_views = hesabix2_post_views_label($post_id);
$post_summary = get_post_meta($post_id, '_hesabix_post_summary', true);
$categories = get_the_category();
$tags = get_the_tags();
$post_url = get_permalink();
$blog_url = hesabix2_blog_url();
$reading_time = hesabix2_post_reading_time($post_id);
$modified = get_the_modified_time('U');
$published = get_the_time('U');
$show_updated = $modified > $published + DAY_IN_SECONDS;
$related_posts = function_exists('hesabix2_seo_related_posts')
? hesabix2_seo_related_posts($post_id, 5)
: array();
$content_raw = apply_filters('the_content', get_post_field('post_content', $post_id));
$prepared = hesabix2_prepare_post_content_with_toc($content_raw);
$post_html = $prepared['html'];
$post_toc = $prepared['toc'];
?>
<main id="main-content" class="single-post-page layout-main min-h-screen bg-slate-50">
<div class="single-reading-progress" aria-hidden="true">
<div id="single-reading-progress-bar" class="single-reading-progress__bar"></div>
</div>
<div class="single-post-header bg-white border-b border-slate-200">
<div class="container mx-auto px-4 py-8">
<div class="single-post-header__inner">
<?php hesabix2_seo_render_breadcrumb('hesabix2-breadcrumb single-breadcrumb'); ?>
<?php if (!empty($categories)) : ?>
<div class="flex flex-wrap gap-2 mb-4">
<?php foreach ($categories as $category) : ?>
<a href="<?php echo esc_url(get_category_link($category->term_id)); ?>" class="single-post-cat px-3 py-1 bg-brand-100 text-brand-800 text-sm font-medium rounded-full hover:bg-brand-200 transition-colors">
<?php echo esc_html($category->name); ?>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
<h1 class="single-title text-3xl lg:text-4xl font-bold text-slate-900 mb-6 leading-tight">
<?php echo esc_html($post_title); ?>
</h1>
<div class="single-meta-row flex flex-wrap items-center gap-4 sm:gap-6 text-sm text-slate-600">
<span class="flex items-center gap-2">
<svg class="w-5 h-5 text-slate-400 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"></path></svg>
<?php esc_html_e('توسط', 'hesabix2'); ?>
<a href="<?php echo esc_url($author_url); ?>" class="single-meta-author-link"><?php echo esc_html($post_author); ?></a>
</span>
<span class="flex items-center gap-2">
<svg class="w-5 h-5 text-slate-400 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true"><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>
<?php if ($show_updated) : ?>
<span class="single-post-updated">
<?php printf(esc_html__('به‌روزرسانی: %s', 'hesabix2'), esc_html(get_the_modified_date('Y/n/d'))); ?>
</span>
<?php endif; ?>
<span class="flex items-center gap-2">
<svg class="w-5 h-5 text-slate-400 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true"><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>
<span id="single-post-views-count"><?php echo esc_html($post_views); ?></span> <?php esc_html_e('بازدید', 'hesabix2'); ?>
</span>
<?php if ($reading_time) : ?>
<span><?php echo esc_html($reading_time); ?></span>
<?php endif; ?>
<?php if (comments_open()) : ?>
<a href="<?php comments_link(); ?>" class="single-meta-comments text-slate-600 hover:text-brand-600 transition-colors">
<?php comments_number(esc_html__('نظر دهید', 'hesabix2'), esc_html__('۱ نظر', 'hesabix2'), '% ' . esc_html__('نظر', 'hesabix2')); ?>
</a>
<?php endif; ?>
</div>
</div>
</div>
</div>
<div class="container mx-auto px-4 py-10 lg:py-12">
<div class="single-post-shell">
<div class="single-post-grid">
<div class="single-post-main">
<article id="post-<?php the_ID(); ?>" <?php post_class('single-article'); ?> data-post-id="<?php echo esc_attr((string) $post_id); ?>">
<?php if (has_post_thumbnail()) : ?>
<figure class="single-featured">
<?php the_post_thumbnail('large', array(
'class' => 'single-featured__img',
'alt' => esc_attr($post_title),
)); ?>
<?php if (get_the_post_thumbnail_caption()) : ?>
<figcaption class="single-featured__caption bg-slate-100 px-4 py-2 text-sm text-slate-600"><?php the_post_thumbnail_caption(); ?></figcaption>
<?php endif; ?>
</figure>
<?php endif; ?>
<div class="single-article__body">
<?php if ($post_summary) : ?>
<div class="single-summary-box bg-brand-50 border-r-4 border-brand-500 p-6 rounded-xl mb-8">
<p class="text-lg text-slate-700 leading-relaxed font-medium m-0">
<?php echo esc_html($post_summary); ?>
</p>
</div>
<?php endif; ?>
<div class="single-content post-content text-slate-800">
<?php echo $post_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</div>
<?php
wp_link_pages(array(
'before' => '<nav class="single-pages mt-6" aria-label="' . esc_attr__('صفحات مطلب', 'hesabix2') . '"><p class="text-sm text-slate-600 mb-2">' . esc_html__('صفحات:', 'hesabix2') . '</p><ul class="flex gap-2 flex-wrap">',
'after' => '</ul></nav>',
));
?>
</div>
<?php if (!empty($tags)) : ?>
<footer class="single-footer mt-8 pt-8 border-t border-slate-200">
<span class="single-footer__label text-sm font-medium text-slate-600"><?php esc_html_e('برچسب‌ها:', 'hesabix2'); ?></span>
<?php foreach ($tags as $tag) : ?>
<a href="<?php echo esc_url(get_tag_link($tag->term_id)); ?>" class="single-tag inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-slate-100 text-slate-700 hover:bg-brand-100 hover:text-brand-700 transition-colors ml-2 mt-2">
<?php echo esc_html($tag->name); ?>
</a>
<?php endforeach; ?>
</footer>
<?php endif; ?>
<?php hesabix2_render_author_box($post_id); ?>
<?php hesabix2_render_blog_cta(); ?>
<div class="single-share mt-12 pt-8 border-t border-slate-200">
<h3 class="single-share-title text-lg font-bold text-slate-900 mb-4"><?php esc_html_e('این مطلب را به اشتراک بگذارید', 'hesabix2'); ?></h3>
<div class="flex flex-wrap gap-3">
<button type="button" class="single-share-btn single-share-copy inline-flex items-center gap-2 px-4 py-2.5 rounded-xl text-white text-sm font-medium hover:opacity-90 transition-opacity" data-copy-url="<?php echo esc_url($post_url); ?>" data-copied-text="<?php esc_attr_e('کپی شد!', 'hesabix2'); ?>">
<span data-copy-label><?php esc_html_e('کپی لینک', 'hesabix2'); ?></span>
</button>
<a href="<?php echo esc_url('https://twitter.com/intent/tweet?text=' . rawurlencode($post_title) . '&url=' . rawurlencode($post_url)); ?>" target="_blank" rel="noopener noreferrer" class="single-share-btn single-share-x inline-flex items-center gap-2 px-4 py-2.5 rounded-xl text-white text-sm font-medium hover:opacity-90 transition-opacity">
X
</a>
<a href="<?php echo esc_url('https://www.linkedin.com/sharing/share-offsite/?url=' . rawurlencode($post_url)); ?>" target="_blank" rel="noopener noreferrer" class="single-share-btn single-share-linkedin inline-flex items-center gap-2 px-4 py-2.5 rounded-xl text-white text-sm font-medium hover:opacity-90 transition-opacity">
<?php esc_html_e('لینکدین', 'hesabix2'); ?>
</a>
<a href="<?php echo esc_url('https://t.me/share/url?url=' . rawurlencode($post_url) . '&text=' . rawurlencode($post_title)); ?>" target="_blank" rel="noopener noreferrer" class="single-share-btn single-share-telegram inline-flex items-center gap-2 px-4 py-2.5 rounded-xl text-white text-sm font-medium hover:opacity-90 transition-opacity">
<?php esc_html_e('تلگرام', 'hesabix2'); ?>
</a>
<a href="<?php echo esc_url('https://wa.me/?text=' . rawurlencode($post_title . ' ' . $post_url)); ?>" target="_blank" rel="noopener noreferrer" class="single-share-btn single-share-whatsapp inline-flex items-center gap-2 px-4 py-2.5 rounded-xl text-white text-sm font-medium hover:opacity-90 transition-opacity">
<?php esc_html_e('واتساپ', 'hesabix2'); ?>
</a>
</div>
</div>
<?php if (comments_open() || get_comments_number()) : ?>
<div class="single-comments-wrap mt-12">
<?php comments_template(); ?>
</div>
<?php endif; ?>
</article>
</div>
<aside class="single-sidebar-col" role="complementary">
<div class="single-sidebar sticky top-8 space-y-6">
<?php if (!empty($post_toc)) : ?>
<div class="single-sidebar-box single-sidebar-box--toc">
<?php hesabix2_render_post_toc($post_toc); ?>
</div>
<?php endif; ?>
<?php if (!empty($related_posts)) : ?>
<div class="single-sidebar-box bg-white rounded-2xl shadow-md border border-slate-100 p-6">
<h3 class="single-sidebar-title text-lg font-bold text-slate-900 mb-5">
<?php esc_html_e('مطالب مرتبط', 'hesabix2'); ?>
</h3>
<ul class="space-y-4 list-none m-0 p-0">
<?php foreach ($related_posts as $related_post) :
$GLOBALS['post'] = $related_post;
setup_postdata($related_post);
?>
<li>
<a href="<?php the_permalink(); ?>" class="single-related-item group flex gap-3 p-3 rounded-xl bg-slate-50 hover:bg-slate-100 transition-colors">
<?php if (has_post_thumbnail()) : ?>
<?php the_post_thumbnail('thumbnail', array(
'class' => 'w-16 h-16 object-cover rounded-lg flex-shrink-0',
'alt' => esc_attr(get_the_title()),
'loading' => 'lazy',
)); ?>
<?php else : ?>
<div class="w-16 h-16 bg-slate-200 rounded-lg flex-shrink-0 flex items-center justify-center" aria-hidden="true">
<svg class="w-8 h-8 text-slate-400" 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>
</div>
<?php endif; ?>
<div class="flex-1 min-w-0">
<h4 class="text-sm font-semibold text-slate-900 group-hover:text-brand-600 transition-colors line-clamp-2"><?php the_title(); ?></h4>
<time class="text-xs text-slate-500 mt-1 block" datetime="<?php echo esc_attr(get_the_date('c')); ?>"><?php echo esc_html(get_the_date('Y/n/d')); ?></time>
</div>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php wp_reset_postdata(); ?>
</div>
<?php endif; ?>
<div class="single-back-blog bg-gradient-to-br from-slate-50 to-slate-100 rounded-2xl p-6 text-center border border-slate-200">
<h3 class="text-lg font-semibold text-slate-900 mb-2"><?php esc_html_e('بازگشت به وبلاگ', 'hesabix2'); ?></h3>
<p class="text-sm text-slate-600 mb-4"><?php esc_html_e('مطالب بیشتری را بخوانید', 'hesabix2'); ?></p>
<a href="<?php echo esc_url($blog_url); ?>" class="single-back-blog-btn inline-flex items-center gap-2 px-5 py-2.5 bg-brand-600 text-white rounded-xl hover:bg-brand-700 transition-colors font-medium text-sm">
<?php esc_html_e('مشاهده همه مطالب', 'hesabix2'); ?>
</a>
</div>
</div>
</aside>
</div>
</div>
</div>
<?php
$prev = get_previous_post();
$next = get_next_post();
if ($prev || $next) :
?>
<div class="container mx-auto px-4 pb-12">
<nav class="single-nav-wrap" aria-label="<?php esc_attr_e('پست‌های قبلی و بعدی', 'hesabix2'); ?>">
<div class="single-nav flex gap-4 justify-between border-t border-slate-200 pt-8">
<?php if ($prev) : ?>
<a href="<?php echo esc_url(get_permalink($prev)); ?>" class="single-nav__item single-nav__prev flex-1 max-w-[50%] p-4 rounded-xl border border-slate-200 hover:border-slate-300 hover:bg-slate-50 transition-colors text-right">
<span class="single-nav__label block text-xs text-slate-500 mb-1"><?php esc_html_e('قبلی', 'hesabix2'); ?></span>
<span class="single-nav__title text-sm font-semibold text-slate-900 line-clamp-2"><?php echo esc_html(get_the_title($prev)); ?></span>
</a>
<?php else : ?>
<span class="flex-1"></span>
<?php endif; ?>
<?php if ($next) : ?>
<a href="<?php echo esc_url(get_permalink($next)); ?>" class="single-nav__item single-nav__next flex-1 max-w-[50%] p-4 rounded-xl border border-slate-200 hover:border-slate-300 hover:bg-slate-50 transition-colors text-left">
<span class="single-nav__label block text-xs text-slate-500 mb-1"><?php esc_html_e('بعدی', 'hesabix2'); ?></span>
<span class="single-nav__title text-sm font-semibold text-slate-900 line-clamp-2"><?php echo esc_html(get_the_title($next)); ?></span>
</a>
<?php endif; ?>
</div>
</nav>
</div>
<?php endif; ?>
</main>
<?php
endif;
endwhile;
?>
<?php if (hesabix2_show_layout_sidebar()) : ?>
<aside class="layout-sidebar" role="complementary">
<?php dynamic_sidebar('sidebar-1'); ?>
</aside>
<?php endif; ?>
</div>
<?php
get_footer();