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',
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user