v1.3 — 拾影独立为 photo 类型
- 新增 photo 自定义文章类型 - page-photos.php 只查询 photo - single-photo.php: 大图 + 诗句 + 虚线分隔 + 标题/作者居中 - photo 导航: ← 更新的(列表左侧) | 更早的(列表右侧) → - 3篇 photo 全新配图,不占用文章封面
This commit is contained in:
@@ -210,6 +210,7 @@ function kjweji_register_photo() {
|
||||
),
|
||||
'public' => true,
|
||||
'has_archive' => false,
|
||||
'rewrite' => array('slug' => 'photo'),
|
||||
'show_in_rest' => true,
|
||||
'supports' => array('title', 'editor', 'author', 'thumbnail'),
|
||||
'menu_position' => 26,
|
||||
|
||||
+34
-32
@@ -1,45 +1,47 @@
|
||||
<?php get_header(); ?>
|
||||
|
||||
<?php
|
||||
// 浏览量 +1
|
||||
$views = (int) get_post_meta(get_the_ID(), 'post_views', true);
|
||||
update_post_meta(get_the_ID(), 'post_views', $views + 1);
|
||||
?>
|
||||
|
||||
<?php while (have_posts()) : the_post(); ?>
|
||||
<div class="article-full">
|
||||
<?php if (get_post_type() === 'post') : ?>
|
||||
<a href="/photos/" class="back-link">← 返回拾影</a>
|
||||
<?php elseif (get_post_type() === 'tucao') : ?>
|
||||
<a href="<?php echo esc_url(get_post_type_archive_link('tucao')); ?>" class="back-link">← 返回微言</a>
|
||||
<?php endif; ?>
|
||||
<div class="photo-detail">
|
||||
<a href="/photos/" class="back-link">← 返回拾影</a>
|
||||
|
||||
<?php if (has_post_thumbnail()) : ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<h1><?php the_title(); ?></h1>
|
||||
|
||||
<div class="article-byline">
|
||||
<span>
|
||||
<?php echo get_avatar(get_the_author_meta('ID'), 20); ?>
|
||||
<a href="<?php echo esc_url(get_author_posts_url(get_the_author_meta('ID'))); ?>">
|
||||
<?php the_author_meta('display_name'); ?>
|
||||
</a>
|
||||
· <?php echo get_the_date('Y-m-d'); ?>
|
||||
</span>
|
||||
<div class="photo-detail__image">
|
||||
<?php if (has_post_thumbnail()) : ?>
|
||||
<?php the_post_thumbnail('medium_large', array('alt' => get_the_title())); ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="article-body">
|
||||
<?php if (get_the_content()) : ?>
|
||||
<div class="photo-detail__body">
|
||||
<?php the_content(); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="comments-section">
|
||||
<?php
|
||||
if (comments_open() || get_comments_number()) {
|
||||
comments_template();
|
||||
}
|
||||
?>
|
||||
<div class="photo-detail__divider"></div>
|
||||
|
||||
<h1 class="photo-detail__title"><?php the_title(); ?></h1>
|
||||
|
||||
<div class="photo-detail__meta">
|
||||
<span><?php echo get_avatar(get_the_author_meta('ID'), 18); ?> <?php the_author_meta('display_name'); ?></span>
|
||||
<span>·</span>
|
||||
<span><?php echo get_the_date('Y-m-d'); ?></span>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
// 拾影列表按日期从新到旧,导航遵循同一方向
|
||||
$left = get_adjacent_post(false, '', false); // 更新的(列表左侧)
|
||||
$right = get_adjacent_post(false, '', true); // 更早的(列表右侧)
|
||||
if ($left || $right) : ?>
|
||||
<div class="photo-detail__nav">
|
||||
<?php if ($left) : ?>
|
||||
<a href="<?php echo get_permalink($left); ?>">← <?php echo get_the_title($left); ?></a>
|
||||
<?php else: ?>
|
||||
<span></span>
|
||||
<?php endif; ?>
|
||||
<?php if ($right) : ?>
|
||||
<a href="<?php echo get_permalink($right); ?>"><?php echo get_the_title($right); ?> →</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endwhile; ?>
|
||||
|
||||
|
||||
@@ -365,3 +365,45 @@ echo "done"
|
||||
border-radius: 50% !important;
|
||||
object-fit: cover !important;
|
||||
}
|
||||
|
||||
.photo-detail { max-width: 800px; margin: 0 auto; }
|
||||
.photo-detail__image { margin-bottom: 24px; border-radius: var(--radius); overflow: hidden; }
|
||||
.photo-detail__image img { width: 100%; height: auto; display: block; }
|
||||
.photo-detail__body { font-size: 1.1rem; line-height: 1.8; color: var(--ink-light); margin-bottom: 24px; font-style: italic; text-align: center; }
|
||||
.photo-detail__meta { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-lighter); padding-top: 16px; border-top: 1px solid var(--border-light); }
|
||||
.photo-detail__meta img { width: 18px !important; height: 18px !important; border-radius: 50% !important; object-fit: cover !important; }
|
||||
.photo-detail__nav { display: flex; justify-content: space-between; margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border-light); font-size: 14px; }
|
||||
.photo-detail__nav a { color: var(--ink-lighter); text-decoration: none; }
|
||||
.photo-detail__nav a:hover { color: var(--cinnabar); }
|
||||
|
||||
.photo-detail .back-link {
|
||||
font-size: 13px;
|
||||
color: var(--ink-lighter);
|
||||
text-decoration: none;
|
||||
margin-bottom: 24px;
|
||||
display: inline-block;
|
||||
font-family: "Noto Sans SC","PingFang SC","Microsoft YaHei",sans-serif;
|
||||
}
|
||||
.photo-detail .back-link:hover { color: var(--cinnabar); }
|
||||
|
||||
.photo-detail__title { font-size: 24px; font-weight: 600; text-align: center; margin-bottom: 10px; }
|
||||
.photo-detail__meta { justify-content: center; }
|
||||
|
||||
.photo-detail__meta span:first-child {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
.photo-detail__meta img {
|
||||
width: 18px !important;
|
||||
height: 18px !important;
|
||||
border-radius: 50% !important;
|
||||
object-fit: cover !important;
|
||||
}
|
||||
|
||||
.photo-detail__divider {
|
||||
width: 60px;
|
||||
margin: 24px auto;
|
||||
border-top: 2px dashed var(--border);
|
||||
}
|
||||
.photo-detail__meta { border-top: none; padding-top: 0; }
|
||||
|
||||
Reference in New Issue
Block a user