-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchive.php
134 lines (112 loc) · 4.63 KB
/
archive.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/**
* @description 当前分类下的文章列表页面
*
* @see https://github.com/Rich4st/base/blob/develop/preview/post-category-list.jpg?raw=true
*
*/
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php bloginfo('name'); ?> | <?php the_title() ?></title>
<meta name="description" content="capalot's blog">
<meta name="keywords" content="blog,博客">
<meta name="og:title" content="<?php bloginfo('name'); ?>-<?php the_title() ?>">
<meta name="og:description" content="capalot's blog">
<meta name="og:keywords" content="blog,博客">
<meta property="og:type" content="website">
<meta property="og:url" content="<?php bloginfo('url') ?>">
<meta property="og:site_name" content="<?php bloginfo('name') ?>">
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/assets/css/tailwind.css">
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/assets/css/swiper-bundle.min.css">
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/assets/css/main.css">
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/assets/css/animate.min.css">
<script src="<?php echo get_template_directory_uri(); ?>/assets/js/index.js"></script>
<?php wp_head(); ?>
</head>
<?php get_header(); ?>
<main>
<section class="px-4 pb-8 lg:max-w-6xl lg:mx-auto">
<?php get_template_part('template_parts/base/base-breadcrumbs2') ?>
<?php
// 查询出当前归档日期下的所有文章
$posts = get_posts(array(
'date_query' => array(
array(
'year' => get_query_var('year'),
'month' => get_query_var('monthnum'),
)
)
));
?>
<ul class="space-y-4">
<?php
foreach ($posts as $post) {
setup_postdata($post);
?>
<?php
// 获取文章标题
$post_title = get_the_title();
// 获取描述
$post_excerpt = get_the_excerpt();
// 获取文章缩略图
$post_thumbnail = get_the_post_thumbnail(get_the_ID(), 'thumbnail', array('class' => 'w-full', 'width' => '100%', 'height' => 'auto'));
// 输出文章链接
$post_link = get_permalink();
// 输出文章日期并格式化为M d, Y
$post_date = get_the_date('M d, Y');
// 输出文章中的第一张图片
$post_content = get_the_content();
$post_content = apply_filters('the_content', $post_content);
$post_content = str_replace(']]>', ']]>', $post_content);
$first_img = '';
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post_content, $matches);
$first_img = $matches[1][0];
// 获取文章作者
$post_author = get_the_author();
// 获取文章评论数
$post_comment_count = get_comments_number();
// 获取文章浏览数
$post_views_count = get_post_meta(get_the_ID(), 'views', true);
// 获取文章点赞数
$post_like_count = get_post_meta(get_the_ID(), 'like', true);
?>
<li class="w-full lg:w-[40rem] list-none flex items-center">
<a class="flex group" href="<?php echo $post_link; ?>">
<div class="min-w-[9.375rem] min-h-[9.375rem]">
<?php if ($first_img) : ?>
<img class="w-[9.375rem] h-[9.375rem] object-cover" src="<?php echo $first_img; ?>" />
<?php else : ?>
<?php echo $post_thumbnail; ?>
<?php endif; ?>
</div>
<div class="ml-4 lg:ml-8 flex flex-col justify-between">
<div>
<h2 class="text-xl font-serif group-hover:underline line-clamp-2"><?php the_title() ?></h2>
<p class="line-clamp-2 text-sm"><?php echo $post_excerpt; ?></p>
</div>
<div class="flex justify-between">
<div class="text-sm text-gray-300">
<span><?php echo the_date() ?></span>
<span><?php echo the_author() ?></span>
</div>
<div class="hidden lg:block">
<span class="text-sm text-gray-300"><?php echo $post_comment_count ?? 0 ?> Comments</span>
<span class="text-sm text-gray-300"><?php echo $post_views_count ?? 0 ?> Views</span>
<span class="text-sm text-gray-300"><?php echo $post_like_count ?? 0 ?> Likes</span>
</div>
</div>
</div>
</a>
</li>
<?php
}
wp_reset_postdata();
?>
</ul>
</section>
</main>
<?php get_footer() ?>