feat: 新增聆韵(music)分类——列表页+单页+CSS+导航+Customizer
This commit is contained in:
@@ -254,6 +254,14 @@ function kjweji_setup_pages() {
|
||||
'meta_input' => ['_wp_page_template' => 'page-photos.php'],
|
||||
]);
|
||||
}
|
||||
// 创建聆韵页
|
||||
if (!get_page_by_path('music')) {
|
||||
wp_insert_post([
|
||||
'post_title' => '聆韵', 'post_name' => 'music',
|
||||
'post_type' => 'page', 'post_status' => 'publish',
|
||||
'meta_input' => ['_wp_page_template' => 'page-music.php'],
|
||||
]);
|
||||
}
|
||||
// 创建导航菜单
|
||||
if (!wp_get_nav_menu_object('主导航')) {
|
||||
$menu_id = wp_create_nav_menu('主导航');
|
||||
@@ -262,6 +270,7 @@ function kjweji_setup_pages() {
|
||||
['笺文', '/articles/'],
|
||||
['微言', '/tucao/'],
|
||||
['拾影', '/photos/'],
|
||||
['聆韵', '/music/'],
|
||||
] as $item) {
|
||||
wp_update_nav_menu_item($menu_id, 0, [
|
||||
'menu-item-title' => $item[0],
|
||||
@@ -319,6 +328,39 @@ add_filter('post_type_link', function($link, $post) {
|
||||
// 匹配 /photo/123/slug/ 格式
|
||||
add_action('init', function() {
|
||||
add_rewrite_rule('^photo/([0-9]+)/([^/]+)/?$', 'index.php?post_type=photo&p=$matches[1]', 'top');
|
||||
|
||||
// ── 自定义文章类型: music(聆韵) ──────────
|
||||
add_action('init', 'kjweji_register_music');
|
||||
function kjweji_register_music() {
|
||||
register_post_type('music', array(
|
||||
'labels' => array(
|
||||
'name' => '聆韵',
|
||||
'singular_name' => '聆韵',
|
||||
'add_new' => '发聆韵',
|
||||
'add_new_item' => '发新聆韵',
|
||||
'edit_item' => '编辑聆韵',
|
||||
),
|
||||
'public' => true,
|
||||
'has_archive' => false,
|
||||
'rewrite' => array('slug' => 'music/%post_id%'),
|
||||
'show_in_rest' => true,
|
||||
'supports' => array('title', 'editor', 'author', 'thumbnail'),
|
||||
'menu_position' => 27,
|
||||
'menu_icon' => 'dashicons-format-audio',
|
||||
));
|
||||
}
|
||||
|
||||
add_filter('post_type_link', function($link, $post) {
|
||||
if ($post->post_type === 'music' && $post->post_status === 'publish') {
|
||||
return home_url(user_trailingslashit('/music/' . $post->ID . '/' . $post->post_name));
|
||||
}
|
||||
return $link;
|
||||
}, 11, 2);
|
||||
|
||||
add_action('init', function() {
|
||||
add_rewrite_rule('^music/([0-9]+)/([^/]+)/?$', 'index.php?post_type=music&p=$matches[1]', 'top');
|
||||
});
|
||||
|
||||
add_rewrite_rule('^photo/([0-9]+)/?$', 'index.php?post_type=photo&p=$matches[1]', 'top');
|
||||
});
|
||||
|
||||
@@ -445,6 +487,14 @@ function kjweji_customize_register($wp_customize) {
|
||||
));
|
||||
$wp_customize->add_control('kjweji_photos_subtitle', array(
|
||||
'label' => '拾影页副标题',
|
||||
));
|
||||
|
||||
$wp_customize->add_setting('kjweji_music_subtitle', array(
|
||||
'default' => '音符落下,余韵未散',
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
));
|
||||
$wp_customize->add_control('kjweji_music_subtitle', array(
|
||||
'label' => '聆韵页副标题',
|
||||
'section' => 'kjweji_settings',
|
||||
'type' => 'text',
|
||||
));
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Template Name: 聆韵列表
|
||||
*/
|
||||
get_header();
|
||||
|
||||
$query = new WP_Query(array(
|
||||
'post_type' => 'music',
|
||||
'posts_per_page' => -1,
|
||||
));
|
||||
?>
|
||||
|
||||
<div class="section-header">
|
||||
<span class="section-title">🎵 聆韵</span>
|
||||
<span class="section-filter" style="font-size:13px;color:var(--ink-lighter);"><?php echo esc_html(get_theme_mod('kjweji_music_subtitle', '音符落下,余韵未散')); ?></span>
|
||||
</div>
|
||||
|
||||
<?php if ($query->have_posts()) : ?>
|
||||
<div class="music-list">
|
||||
<?php while ($query->have_posts()) : $query->the_post(); ?>
|
||||
<a href="<?php the_permalink(); ?>" class="music-item">
|
||||
<?php if (has_post_thumbnail()) : ?>
|
||||
<div class="music-item__cover">
|
||||
<?php the_post_thumbnail('thumbnail', array('alt' => get_the_title())); ?>
|
||||
<span class="music-item__play">▶</span>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<div class="music-item__cover music-item__cover--empty">
|
||||
<span>🎵</span>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<div class="music-item__body">
|
||||
<span class="music-item__title"><?php the_title(); ?></span>
|
||||
<span class="music-item__author"><?php the_author_meta('display_name'); ?> · <?php echo get_the_date('Y-m-d'); ?></span>
|
||||
</div>
|
||||
</a>
|
||||
<?php endwhile; ?>
|
||||
</div>
|
||||
<?php wp_reset_postdata(); ?>
|
||||
<?php else : ?>
|
||||
<div class="music-empty">
|
||||
<span class="music-empty__icon">🎵</span>
|
||||
<p>尚无韵律,静待佳音</p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php get_footer(); ?>
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php get_header(); ?>
|
||||
|
||||
<?php while (have_posts()) : the_post(); ?>
|
||||
<article class="music-detail">
|
||||
<a href="/music/" class="back-link">← 返回聆韵</a>
|
||||
|
||||
<?php if (has_post_thumbnail()) : ?>
|
||||
<div class="music-detail__cover">
|
||||
<?php the_post_thumbnail('medium_large', array('alt' => get_the_title())); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<h1 class="music-detail__title"><?php the_title(); ?></h1>
|
||||
|
||||
<div class="music-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>
|
||||
|
||||
<div class="music-detail__body">
|
||||
<?php the_content(); ?>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
$left = get_adjacent_post(false, '', false);
|
||||
$right = get_adjacent_post(false, '', true);
|
||||
if ($left || $right) : ?>
|
||||
<div class="music-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; ?>
|
||||
</article>
|
||||
<?php endwhile; ?>
|
||||
|
||||
<?php get_footer(); ?>
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Theme Name: 空笺未寄
|
||||
Version: 0.16.8
|
||||
Version: 0.17.0
|
||||
Requires at least: 6.0
|
||||
Requires PHP: 7.4
|
||||
License: MIT
|
||||
@@ -304,6 +304,31 @@ echo "done"
|
||||
/* Gallery image fix */
|
||||
.gallery-img { display:block !important; width:100% !important; height:auto !important; }
|
||||
.gallery-empty { display:flex; align-items:center; justify-content:center; min-height:160px; color:var(--ink-lighter); background:linear-gradient(135deg, #faf7f0 0%, #f0ebe0 100%); }
|
||||
/* ── 聆韵 ── */
|
||||
.music-list { display:flex; flex-direction:column; gap:0; }
|
||||
.music-item { display:flex; align-items:center; gap:16px; padding:18px 0; border-bottom:1px solid var(--border-light); text-decoration:none; color:inherit; transition:padding 0.25s; }
|
||||
.music-item:hover { padding-left:8px; border-bottom-color:var(--cinnabar-light); }
|
||||
.music-item__cover { width:60px; height:60px; border-radius:var(--radius); overflow:hidden; flex-shrink:0; position:relative; background:linear-gradient(135deg, #e8dccf 0%, #d5c4aa 100%); }
|
||||
.music-item__cover img { width:100%; height:100%; object-fit:cover; }
|
||||
.music-item__cover--empty { display:flex; align-items:center; justify-content:center; font-size:28px; }
|
||||
.music-item__play { position:absolute; inset:0; display:flex; align-items:center; justify-content:center; background:rgba(0,0,0,0.3); color:#fff; font-size:20px; opacity:0; transition:opacity 0.2s; }
|
||||
.music-item:hover .music-item__play { opacity:1; }
|
||||
.music-item__body { display:flex; flex-direction:column; gap:4px; }
|
||||
.music-item__title { font-size:16px; letter-spacing:0.05em; }
|
||||
.music-item__author { font-size:12px; color:var(--ink-lighter); }
|
||||
.music-empty { display:flex; flex-direction:column; align-items:center; justify-content:center; min-height:160px; color:var(--ink-lighter); gap:12px; }
|
||||
.music-empty__icon { font-size:48px; opacity:0.4; }
|
||||
.music-detail { max-width:680px; margin:0 auto; }
|
||||
.music-detail__cover { border-radius:var(--radius); overflow:hidden; margin-bottom:24px; }
|
||||
.music-detail__cover img { width:100%; height:auto; display:block; }
|
||||
.music-detail__title { font-size:24px; margin-bottom:12px; }
|
||||
.music-detail__meta { display:flex; align-items:center; gap:8px; font-size:13px; color:var(--ink-lighter); margin-bottom:24px; }
|
||||
.music-detail__body { font-size:15px; line-height:1.9; color:var(--ink); margin-bottom:32px; }
|
||||
.music-detail__body audio, .music-detail__body video { width:100%; margin:16px 0; border-radius:var(--radius); }
|
||||
.music-detail__nav { display:flex; justify-content:space-between; padding:24px 0; border-top:1px solid var(--border-light); }
|
||||
.music-detail__nav a { color:var(--ink-light); text-decoration:none; font-size:14px; }
|
||||
.music-detail__nav a:hover { color:var(--cinnabar); }
|
||||
|
||||
|
||||
/* Card & pinned cover image constraints */
|
||||
.card-cover img, .pinned-cover img, .article-cover img, .gallery-img {
|
||||
|
||||
Reference in New Issue
Block a user