v1.2 — 拾影独立为 photo 类型
- 新增 photo 自定义文章类型(专属拾影) - page-photos.php 只查询 photo - single-photo.php 无封面图、返回拾影链接 - 月光森林/海岸灯塔/古镇巷子 转为 photo 类型 - 首页和笺文不包含 photo
This commit is contained in:
@@ -196,3 +196,23 @@ function kjweji_setup_pages() {
|
||||
}
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
// 自定义文章类型:拾影
|
||||
add_action('init', 'kjweji_register_photo');
|
||||
function kjweji_register_photo() {
|
||||
register_post_type('photo', array(
|
||||
'labels' => array(
|
||||
'name' => '拾影',
|
||||
'singular_name' => '拾影',
|
||||
'add_new' => '发拾影',
|
||||
'add_new_item' => '发新拾影',
|
||||
'edit_item' => '编辑拾影',
|
||||
),
|
||||
'public' => true,
|
||||
'has_archive' => false,
|
||||
'show_in_rest' => true,
|
||||
'supports' => array('title', 'editor', 'author', 'thumbnail'),
|
||||
'menu_position' => 26,
|
||||
'menu_icon' => 'dashicons-format-gallery',
|
||||
));
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ get_header();
|
||||
|
||||
// 获取所有带特色图片的文章(普通文章 + 可选 tucao)
|
||||
$photo_query = new WP_Query(array(
|
||||
'post_type' => 'post',
|
||||
'post_type' => 'photo',
|
||||
'posts_per_page' => -1,
|
||||
'meta_key' => '_thumbnail_id',
|
||||
));
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?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; ?>
|
||||
|
||||
<?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>
|
||||
|
||||
<div class="article-body">
|
||||
<?php the_content(); ?>
|
||||
</div>
|
||||
|
||||
<div class="comments-section">
|
||||
<?php
|
||||
if (comments_open() || get_comments_number()) {
|
||||
comments_template();
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endwhile; ?>
|
||||
|
||||
<?php get_footer(); ?>
|
||||
Reference in New Issue
Block a user