Initial WordPress theme

This commit is contained in:
2026-06-25 15:57:22 +08:00
commit 043faa8b98
19 changed files with 1161 additions and 0 deletions

64
single.php Normal file
View File

@@ -0,0 +1,64 @@
<?php get_header(); ?>
<div class="pt-24 min-h-screen bg-apple-grey animate-fade-in">
<div class="max-w-4xl mx-auto px-4 md:px-6 pb-20">
<?php while (have_posts()): the_post(); $cats = get_the_category(); $primary = !empty($cats) ? $cats[0] : null; $tags = get_the_tags(); ?>
<a href="<?php echo esc_url(gx_knowledge_url()); ?>" class="inline-flex items-center gap-2 text-gray-500 hover:text-apple-blue mb-8 transition-colors">
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg>返回知识库
</a>
<article <?php post_class('bg-white rounded-3xl shadow-sm overflow-hidden'); ?>>
<?php if (has_post_thumbnail()): ?><div class="w-full h-48 md:h-72 overflow-hidden"><?php the_post_thumbnail('large', array('class' => 'w-full h-full object-cover')); ?></div><?php endif; ?>
<div class="p-6 md:p-10 border-b border-gray-100">
<div class="flex flex-wrap items-center gap-2 mb-4">
<?php if ($primary): ?><span class="bg-apple-blue/10 text-apple-blue text-xs font-medium px-3 py-1 rounded-full"><?php echo esc_html($primary->name); ?></span><?php endif; ?>
<?php if (is_sticky(get_the_ID())): ?><span class="bg-orange-100 text-orange-600 text-xs font-medium px-3 py-1 rounded-full">置顶</span><?php endif; ?>
<?php if ($tags): foreach (array_slice($tags, 0, 3) as $tag): ?><a href="<?php echo esc_url(get_tag_link($tag)); ?>" class="bg-gray-100 text-gray-600 text-xs px-2 py-0.5 rounded-full hover:text-apple-blue">#<?php echo esc_html($tag->name); ?></a><?php endforeach; endif; ?>
</div>
<h1 class="text-2xl md:text-3xl font-bold text-gray-900 mb-6 leading-tight"><?php the_title(); ?></h1>
<div class="flex flex-wrap items-center gap-4 text-sm text-gray-500">
<span class="flex items-center gap-1"><span class="w-6 h-6 bg-apple-blue/10 rounded-full flex items-center justify-center text-xs text-apple-blue font-medium">G</span><?php the_author(); ?></span>
<span class="flex items-center gap-1"><?php echo esc_html(get_the_date('Y年n月j日')); ?></span>
<span class="flex items-center gap-1"><?php echo esc_html(gx_format_views(gx_get_views())); ?> 阅读</span>
</div>
</div>
<?php if (has_excerpt()): ?><div class="px-6 md:px-10 py-4 bg-blue-50/50 border-b border-blue-100"><p class="text-sm text-blue-800 leading-relaxed italic"><?php echo esc_html(get_the_excerpt()); ?></p></div><?php endif; ?>
<div class="p-6 md:p-10"><div class="prose prose-gongxue max-w-none"><?php the_content(); ?></div></div>
<div class="p-6 md:p-10 bg-gray-50 border-t border-gray-100 flex items-center justify-between">
<span class="text-gray-500">知识库</span>
<button class="gx-share flex items-center gap-2 px-6 py-2 bg-white border border-gray-200 rounded-full text-gray-600 hover:bg-gray-50 transition-colors" data-url="<?php the_permalink(); ?>" data-title="<?php the_title_attribute(); ?>">分享文章</button>
</div>
</article>
<?php
$related_args = array(
'post__not_in' => array(get_the_ID()),
'posts_per_page' => 3,
'ignore_sticky_posts' => true,
);
if ($primary) {
$related_args['cat'] = $primary->term_id;
}
$related = new WP_Query($related_args);
if (!$related->have_posts()) {
$related = new WP_Query(array(
'post__not_in' => array(get_the_ID()),
'posts_per_page' => 3,
'ignore_sticky_posts' => true,
));
}
if ($related->have_posts()):
?>
<section class="mt-10">
<h2 class="text-xl font-bold text-apple-dark mb-6">相关文章</h2>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<?php while ($related->have_posts()): $related->the_post(); $rcats = get_the_category(); $rname = !empty($rcats) ? $rcats[0]->name : '文章'; ?>
<a href="<?php the_permalink(); ?>" class="bg-white p-5 rounded-2xl shadow-sm hover:shadow-md transition-all group">
<h3 class="font-semibold text-gray-900 group-hover:text-apple-blue transition-colors line-clamp-2 text-sm"><?php the_title(); ?></h3>
<div class="flex items-center gap-3 mt-2 text-xs text-gray-400"><span><?php echo esc_html($rname); ?></span><span><?php echo esc_html(gx_format_views(gx_get_views($related->post->ID))); ?> 阅读</span></div>
</a>
<?php endwhile; wp_reset_postdata(); ?>
</div>
</section>
<?php endif; ?>
<?php endwhile; ?>
</div>
</div>
<?php get_footer(); ?>