diff --git a/functions.php b/functions.php
index 1599e71..134e91c 100644
--- a/functions.php
+++ b/functions.php
@@ -210,10 +210,25 @@ function kjweji_register_photo() {
),
'public' => true,
'has_archive' => false,
- 'rewrite' => array('slug' => 'photo'),
+ 'rewrite' => array('slug' => 'photo/%post_id%'),
'show_in_rest' => true,
'supports' => array('title', 'editor', 'author', 'thumbnail'),
'menu_position' => 26,
'menu_icon' => 'dashicons-format-gallery',
));
}
+
+
+
+add_filter('post_type_link', function($link, $post) {
+ if ($post->post_type === 'photo' && $post->post_status === 'publish') {
+ return home_url(user_trailingslashit('/photo/' . $post->ID . '/' . $post->post_name));
+ }
+ return $link;
+}, 10, 2);
+
+// 匹配 /photo/123/slug/ 格式
+add_action('init', function() {
+ add_rewrite_rule('^photo/([0-9]+)/([^/]+)/?$', 'index.php?post_type=photo&p=$matches[1]', 'top');
+ add_rewrite_rule('^photo/([0-9]+)/?$', 'index.php?post_type=photo&p=$matches[1]', 'top');
+});
diff --git a/page-photos.php b/page-photos.php
index ab2e55c..cfa90ab 100644
--- a/page-photos.php
+++ b/page-photos.php
@@ -9,7 +9,6 @@ get_header();
$photo_query = new WP_Query(array(
'post_type' => 'photo',
'posts_per_page' => -1,
- 'meta_key' => '_thumbnail_id',
));
?>
diff --git a/single-photo.php b/single-photo.php
index 86bec24..22e2c65 100644
--- a/single-photo.php
+++ b/single-photo.php
@@ -1,18 +1,53 @@
-
+ ]+src="([^"]+)"/', $content_raw, $m)) {
+ foreach ($m[1] as $url) {
+ $key = basename(parse_url($url, PHP_URL_PATH));
+ if (!isset($seen[$key])) {
+ $seen[$key] = true;
+ $gallery[] = $url;
+ }
+ }
+ }
+ // 特色图(如果没有出现在正文中则加入)
+ if (has_post_thumbnail()) {
+ $thumb_url = get_the_post_thumbnail_url(null, 'large');
+ $key = basename(parse_url($thumb_url, PHP_URL_PATH));
+ if (!isset($seen[$key])) {
+ $gallery[] = $thumb_url;
+ }
+ }
+ $gallery_json = json_encode($gallery);
+ $content = $content_raw;
+ ?>
+
+
← 返回拾影
-
-
- get_the_title())); ?>
-
+ ]+src=/', $content) && has_post_thumbnail()) : ?>
+
+ get_the_title())); ?>
+
-
+
-
+ ]+src="([^"]+)"[^>]*>/', '

', $content);
+ echo $content;
+ ?>
@@ -27,9 +62,8 @@
@@ -45,4 +79,93 @@
+
+
+
+
×
+
+
‹
+
›
+
+
+
+
![]()
+
+
+
+
+
+
+
diff --git a/style.css b/style.css
index 3244c16..723bbd2 100644
--- a/style.css
+++ b/style.css
@@ -407,3 +407,84 @@ echo "done"
border-top: 2px dashed var(--border);
}
.photo-detail__meta { border-top: none; padding-top: 0; }
+
+.photo-detail__body img {
+ display: block;
+ width: 100%;
+ height: auto;
+ margin: 20px 0;
+ border-radius: var(--radius);
+}
+.photo-detail__body p {
+ margin: 16px 0;
+ text-align: center;
+ font-style: italic;
+ color: var(--ink-light);
+}
+
+/* 照片灯箱 */
+.photo-lightbox {
+ display: none;
+ position: fixed; top: 0; left: 0; width: 100%; height: 100%;
+ background: #000;
+ z-index: 9999;
+ justify-content: center; align-items: center;
+}
+.photo-lightbox.active { display: flex; }
+.photo-lightbox__content { max-width: 90vw; max-height: 90vh; }
+.photo-lightbox__content img { max-width: 90vw; max-height: 85vh; object-fit: contain; border-radius: var(--radius); }
+.photo-lightbox__close { position: absolute; top: 24px; right: 36px; font-size: 42px; color: #fff; cursor: pointer; opacity: 0.8; z-index: 2; }
+.photo-lightbox__close:hover { opacity: 1; }
+.photo-lightbox__counter { position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%); color: #fff; font-size: 14px; opacity: 0.7; z-index: 2; }
+.photo-lightbox__nav { position: absolute; top: 50%; transform: translateY(-50%); font-size: 56px; color: #fff; cursor: pointer; user-select: none; padding: 24px; opacity: 0.7; z-index: 2; }
+.photo-lightbox__nav:hover { opacity: 1; }
+.photo-lightbox__prev { left: 16px; }
+.photo-lightbox__next { right: 16px; }
+
+/* 图片可点击提示 */
+.photo-detail__image { cursor: zoom-in; }
+.photo-detail__body img { cursor: zoom-in; }
+
+
+.photo-lightbox__postnav {
+ position: absolute;
+ bottom: 18px;
+ left: 0; right: 0;
+ display: flex;
+ justify-content: space-between;
+ padding: 0 40px;
+ z-index: 2;
+}
+.photo-lightbox__postnav a {
+ color: rgba(255,255,255,0.6);
+ text-decoration: none;
+ font-size: 14px;
+}
+.photo-lightbox__postnav a:hover { color: #fff; }
+.photo-lightbox__postnav span { color: transparent; }
+.photo-lightbox__counter { bottom: 60px; }
+
+.photo-lightbox__brand {
+ position: absolute;
+ top: 24px;
+ left: 36px;
+ color: rgba(255,255,255,0.25);
+ font-size: 16px;
+ letter-spacing: 0.1em;
+ z-index: 2;
+ font-family: "Noto Serif SC", "STSong", "Songti SC", serif;
+}
+
+.photo-lightbox__info {
+ text-align: center;
+ margin-bottom: 16px;
+}
+.photo-lightbox__photo-title {
+ color: rgba(255,255,255,0.5);
+ font-size: 15px;
+ font-weight: 400;
+ letter-spacing: 0.04em;
+}
+
+
+.photo-lightbox__content img { border-radius: 6px; }