打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
wordpress 添加“归档”页面
wordpress “归档”页面,
特点:
01.访问速度快。
02.显示每月文章数。
03.显示每篇文章的评论数。
效果:见我网站的存档页
下面是详细步骤
1. 把下面的函数代码扔进主题的 functions.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
135
136
137
138
139
140
141
class hacklog_archives
{
function GetPosts()
{
global  $wpdb;
if ( $posts = wp_cache_get( 'posts', 'ihacklog-clean-archives' ) )
return $posts;
$query="SELECT DISTINCT ID,post_date,post_date_gmt,comment_count,comment_status,post_password FROM $wpdb->posts WHERE post_type='post' AND post_status = 'publish' AND comment_status = 'open'";
$rawposts =$wpdb->get_results( $query, OBJECT );
foreach( $rawposts as $key => $post ) {
$posts[ mysql2date( 'Y.m', $post->post_date ) ][] = $post;
$rawposts[$key] = null;
}
$rawposts = null;
wp_cache_set( 'posts', $posts, 'ihacklog-clean-archives' );;
return $posts;
}
function PostList( $atts = array() )
{
global $wp_locale;
global $hacklog_clean_archives_config;
$atts = shortcode_atts(array(
'usejs'        => $hacklog_clean_archives_config['usejs'],
'monthorder'   => $hacklog_clean_archives_config['monthorder'],
'postorder'    => $hacklog_clean_archives_config['postorder'],
'postcount'    => '1',
'commentcount' => '1',
), $atts);
$atts=array_merge(array('usejs'=>1,'monthorder'   =>'new','postorder'    =>'new'),$atts);
$posts = $this->GetPosts();
( 'new' == $atts['monthorder'] ) ? krsort( $posts ) : ksort( $posts );
foreach( $posts as $key => $month ) {
$sorter = array();
foreach ( $month as $post )
$sorter[] = $post->post_date_gmt;
$sortorder = ( 'new' == $atts['postorder'] ) ? SORT_DESC : SORT_ASC;
array_multisort( $sorter, $sortorder, $month );
$posts[$key] = $month;
unset($month);
}
$html = '</pre>
<div class="car-container';      if ( 1 == $atts['usejs'] ) $html .= ' car-collapse';        $html .= '">'. "\n";
if ( 1 == $atts['usejs'] ) $html .= '<a class="car-toggler" href="#">展开所有月份'."</a>\n\n";
$html .= '
<ul class="car-list">
<ul class="car-list">' . "\n";</ul>
</ul>
<ul class="car-list">
<ul class="car-list">$firstmonth = TRUE;</ul>
</ul>
<ul class="car-list">
<ul class="car-list">foreach( $posts as $yearmonth => $posts ) {</ul>
</ul>
<ul class="car-list">
<ul class="car-list">list( $year, $month ) = explode( '.', $yearmonth );</ul>
</ul>
<ul class="car-list">
<ul class="car-list">$firstpost = TRUE;</ul>
</ul>
<ul class="car-list">
<ul class="car-list">foreach( $posts as $post ) {</ul>
</ul>
<ul class="car-list">
<ul class="car-list">if ( TRUE == $firstpost ) {</ul>
</ul>
<ul class="car-list">
<ul class="car-list">
<ul class="car-list">$html .= '</ul>
</ul>
</ul>
<ul class="car-list">
<ul class="car-list">
<li><span class="car-yearmonth">+ ' . sprintf( __('%1$s %2$d'), $wp_locale->get_month($month), $year );
if ( '0' != $atts['postcount'] )
{
$html .= ' <span title="文章数量">(共' . count($posts) . '篇文章)</span>';
}
$html .= "</span>\n
<ul class="car-monthlisting">
<ul class="car-monthlisting">\n";</ul>
</ul>
<ul class="car-monthlisting">
<ul class="car-monthlisting">$firstpost = FALSE;</ul>
</ul>
<ul class="car-monthlisting">
<ul class="car-monthlisting">}</ul>
</ul>
<ul class="car-monthlisting">
<ul class="car-monthlisting">
<ul class="car-monthlisting">$html .= '</ul>
</ul>
</ul>
<ul class="car-monthlisting">
<ul class="car-monthlisting">
<li>' . mysql2date( 'd', $post->post_date ) . '日: <a href="' . get_permalink( $post->ID ) . '" target="_blank">' . get_the_title( $post->ID ) . '</a>';
if ( '0' != $atts['commentcount'] && ( 0 != $post->comment_count || 'closed' != $post->comment_status ) && empty($post->post_password) )
$html .= ' <span title="评论数量">(' . $post->comment_count . '条评论)</span>';
$html .= "</li>
</ul>
</ul>
<ul class="car-monthlisting">
<ul class="car-monthlisting">\n";</ul>
</ul>
<ul class="car-monthlisting">
<ul class="car-monthlisting">}</ul>
</ul>
<ul class="car-monthlisting">$html .= "</ul>
\n</li>
</ul>
</ul>
<ul class="car-list">
<ul class="car-list">\n";</ul>
</ul>
<ul class="car-list">
<ul class="car-list">}</ul>
</ul>
<ul class="car-list">$html .= "</ul>
\n</div>
<pre>\n";
return $html;
}
function PostCount()
{
$num_posts = wp_count_posts( 'post' );
return number_format_i18n( $num_posts->publish );
}
}
if(!empty($post->post_content))
{
$all_config=explode(';',$post->post_content);
foreach($all_config as $item)
{
$temp=explode('=',$item);
$hacklog_clean_archives_config[trim($temp[0])]=htmlspecialchars(strip_tags(trim($temp[1])));
}
}
else
{
$hacklog_clean_archives_config=array('usejs'=>1,'monthorder'   =>'new','postorder'    =>'new');
}
$hacklog_archives=new hacklog_archives();
2. 复制一份主题的 page.php 更名为 archives.php,然后在最顶端加入:
1
<!--?php /* Template Name: archives */ ?-->
在<?php get_header();?>下面,加入如下代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<script type="text/javascript">
/* <![CDATA[ */
jQuery(document).ready(function() {
jQuery('.car-collapse').find('.car-monthlisting').hide();
jQuery('.car-collapse').find('.car-monthlisting:first').show();
jQuery('.car-collapse').find('.car-yearmonth').click(function() {
jQuery(this).next('ul').slideToggle('fast');
});
jQuery('.car-collapse').find('.car-toggler').click(function() {
if ( '展开所有月份' == jQuery(this).text() ) {
jQuery(this).parent('.car-container').find('.car-monthlisting').show();
jQuery(this).text('折叠所有月份');
}
else {
jQuery(this).parent('.car-container').find('.car-monthlisting').hide();
jQuery(this).text('展开所有月份');
}
return false;
});
});
/* ]]> */
</script>
再然后找到类似 <?php content(); ?>,在其下面加入如下代码:
1
<!--?php echo $hacklog_archives--->PostList();?>
3.进wp后台添加一新页面,在右侧栏模板选择 archives。
剩下的就是对CSS进行调整以达到你想要的效果,比如字体大小,颜色等等。
好了,弄完,收工。
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
WordPress 教程
程序
superslide滚动插件使用记录-产品滚动-图片滚动
采用Jquery+Ajax+PHP+MySQL实现分类列表管理 下
JQUERY 获取当前焦点对象属性,
JQuery实现动态生成树形菜单
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服