<?php
/**
 * نی‌نی بلاگ - پوسته کودکانه برای تایپ‌چو
 * 
 * @package Typecho Nini Blog Theme
 * @author Pourdaryaei
 * @version 1.3
 * @link http://typecho.ir
 */
if (!defined('__TYPECHO_ROOT_DIR__')) exit;

$this->need('header.php');
$options = $this->options;
?>
<!-- آخرین مقالات -->
<section class="posts-section">

    
    <div class="row posts-grid">
        <?php while($this->next()): ?>
        <div class="col-md-6 col-lg-6">
            <article class="blog-card">
                <div class="blog-card-img">
                    <a href="<?php $this->permalink(); ?>">
                        <img src="<?php echo getPostImage($this); ?>" alt="<?php $this->title(); ?>" loading="lazy">
                    </a>
                    <?php
                    $db = Typecho_Db::get();
                    $categories = $db->fetchAll($db->select()->from('table.metas')
                        ->join('table.relationships', 'table.relationships.mid = table.metas.mid')
                        ->where('table.relationships.cid = ?', $this->cid)
                        ->where('table.metas.type = ?', 'category'));

                    if (!empty($categories)) {
                        $catNames = array_column($categories, 'name');
                        echo '<span class="blog-card-category">' . implode('، ', $catNames) . '</span>';
                    }
                    ?>
                </div>
                
                <div class="blog-card-body">
                    <?php
                    $viewsCounterActive = false;
                    $plugins = Typecho_Plugin::export();
                    if (isset($plugins['activated']['ViewsCounter'])) {
                        $viewsCounterActive = true;
                    }
                    ?>
                    
                    <div class="blog-card-meta">
                        <span><i class="fa-regular fa-user"></i> <a href="<?php $this->author->permalink(); ?>"><?php $this->author(); ?></a></span>
                        <span><i class="fa-regular fa-calendar"></i> <?php echo getLocalizedDate($this->created); ?></span>
                        <?php if ($viewsCounterActive): ?>
                            <span><i class="fa-regular fa-eye"></i> <?php echo toPersianNumbers(ViewsCounter_Plugin::getViewsById($this->cid)); ?></span>
                        <?php endif; ?>
                        <span><i class="fa-regular fa-comment"></i> <?php $this->commentsNum('۰', '۱', '%d'); ?></span>
                    </div>
                    
                    <h2 class="blog-card-title">
                        <a href="<?php $this->permalink(); ?>"><?php $this->title(); ?></a>
                    </h2>
                    
                    <p class="blog-card-excerpt"><?php $this->excerpt(120, '...'); ?></p>
                    
                    <a href="<?php $this->permalink(); ?>" class="read-more-btn">
                        ادامه مطلب <i class="fa-solid fa-arrow-left"></i>
                    </a>
                </div>
            </article>
        </div>
        <?php endwhile; ?>
    </div>
</section>

<!-- صفحه‌بندی -->
<nav class="nini-pagination">
    <?php $this->pageNav(
        '<i class="fa-solid fa-chevron-right"></i>',
        '<i class="fa-solid fa-chevron-left"></i>',
        2,
        '...',
        array(
            'wrapTag' => 'ul',
            'wrapClass' => 'page-navigator',
            'itemTag' => 'li',
            'textTag' => 'span',
            'currentClass' => 'current',
            'prevClass' => 'prev',
            'nextClass' => 'next'
        )
    ); ?>
</nav>

<?php $this->need('footer.php'); ?>