<?php 
/*
* Template Name: 隐私政策
*/
?>
<?php get_header(); ?>
<div class="single-page-container">
    <!-- 左侧文章列表侧边栏 -->
    <aside class="sidebar-left" role="complementary" aria-label="相关文章">
        <header class="sidebar-header">
            <nav aria-label="返回导航">
                <a href="/category/news-center" 
                   class="back-link" 
                   aria-label="返回新闻中心">
                    <svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true">
                        <path d="M10 12L6 8L10 4" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                    </svg>
                    <span>返回新闻</span>
                </a>
            </nav>
        </header>
        
        <section class="recent-articles" aria-label="最新文章">
            <h2 class="screen-reader-text">最新文章列表</h2>
            <?php
            // 优化查询参数
            $recent_posts = new WP_Query(array(
                'post_type' => 'post',
                'posts_per_page' => 6,
                'post_status' => 'publish',
                'post__not_in' => array(get_the_ID()),
                'no_found_rows' => true, // 性能优化：不计算总数
                'update_post_meta_cache' => false, // 性能优化：不缓存meta
                'update_post_term_cache' => false, // 性能优化：不缓存terms
                'fields' => 'ids' // 只获取ID，减少内存使用
            ));
            
            if ($recent_posts->have_posts()) :
                // 重新获取完整文章数据（只针对需要的字段）
                $post_ids = $recent_posts->posts;
                $posts_data = get_posts(array(
                    'include' => $post_ids,
                    'post_type' => 'post',
                    'post_status' => 'publish',
                    'orderby' => 'post__in'
                ));
                
                foreach ($posts_data as $post) :
                    setup_postdata($post);
            ?>
            <article class="article-item">
                <div class="article-content">
                    <h3 class="article-title">
                        <a href="<?php echo esc_url(get_permalink($post->ID)); ?>" 
                           aria-label="阅读文章：<?php echo esc_attr(get_the_title($post->ID)); ?>">
                            <?php echo get_the_title($post->ID); ?>
                        </a>
                    </h3>
                    <time class="article-date" datetime="<?php echo get_the_date('c', $post->ID); ?>">
                        <?php echo get_the_date('Y-m-d', $post->ID); ?>
                    </time>
                </div>
            </article>
            <?php
                endforeach;
                wp_reset_postdata();
            else :
            ?>
            <p class="no-articles">暂无相关文章</p>
            <?php endif; ?>
        </section>
    </aside>
    
    <!-- 右侧主要内容区域 -->
    <main class="main-content" role="main">
        <article class="article-content">
            <header class="article-header">
                <h1 class="article-title"><?php the_title(); ?></h1>
                <div class="article-meta">
                    <time class="article-time" datetime="<?php echo get_the_date('c'); ?>">
                        <span class="screen-reader-text">发布时间：</span>
                        <?php the_time('Y-m-d H:i:s'); ?>
                    </time>
                    <?php if (get_the_category()) : ?>
                    <div class="article-categories">
                        <span class="screen-reader-text">分类：</span>
                        <?php the_category(', '); ?>
                    </div>
                    <?php endif; ?>
                </div>
            </header>
            
            <div class="article-body">
                <?php the_content(); ?>
            </div>
            
            <?php if (get_the_tags()) : ?>
            <footer class="article-footer">
                <div class="article-tags">
                    <span class="tags-label">标签：</span>
                    <?php the_tags('', ', ', ''); ?>
                </div>
            </footer>
            <?php endif; ?>
        </article>
    </main>
</div>
<?php get_footer(); ?>