wordpress 添加“归档”页面

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

wordpress 添加“归档”页面
wordpress “归档”页面,特点:01.访问速度快。

02.显示每月文章数。

03.显示每篇文章的评论数。

效果:见我网站的存档页下面是详细步骤1. 把下面的函数代码扔进主题的functions.php 里面:1234567891011121314151617181920212223242526272829303 132333435363738394041424344454647484950515253545556 575859606162636465666768697071727374757677787980818 283848586878889909192939495969798991001011021031041 0510610710810911011111211311411511611711811912012112 212312412512612712812913013113213313413513613713813 9140141class 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,p ost_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(!emp ty($post->post_content)){ $all_config=explode(';',$post->post_content); foreach($all_config as $item)
{ $temp=explode('=',$item);
$hacklog_clean_archives_config[trim($temp[0])]=htmlspecialch ars(strip_tags(trim($temp[1]))); }}else{ $hacklog_clean _archives_config=array('usejs'=>1,'monthorder'
=>'new','postorder'
=>'new');}$hacklog_archives=new hacklog_archives();。

相关文档
最新文档