Smart Archives 增强
安装了 Justin Blanton 开发的 smart archives 插件, 发现这个插件对中文和韩文支持不佳。我给做了点小修改,并且对他的一些小缺陷也进行了补正。最后的效果请看 http://www.doyj.com/archives/。
安装方法如下:
- 将下面的代码拷贝并存成文件smartarchives.php
- 将smartarchives.php 上载到你的plugin目录
- 到控制面板激活Smart Archives 插件
- 在适当的地方插入smartArchives()函数调用。
这个函数有两个参数,第一个在”both”, “block”,”list”中选择,默认为both 第二个是要排除的分类id.
下面就是修改后的代码:
- <?php
- /*
- Plugin Name: Smart Archives
- Version: 1.5
- Plugin URI: http://justinblanton.com/projects/smartarchives/
- Description: A simple, clean, and future-proof way to present your archives.
- Author: Justin Blanton
- Author URI: http://justinblanton.com
- */
- function smartArchives($format='both', $catID='') {
- global $tableposts, $wpdb, $PHP_SELF , $month ;
- setlocale(LC_ALL,WPLANG); // set localization language
- // set the URI of your archives; this might not need to be changed (currently, it's http://yoursite.com/archives/)
- $now = gmdate('Y-m-d H:i:s'); // get the current GMT date
- if (($format == 'both') || ($format == 'block')) { // check to see if we are supposed to display the block
- $qy = mysql_query("SELECT distinct year(post_date) as year, post_status
- FROM $tableposts
- WHERE post_status='publish'
- AND post_date <= NOW()
- ORDER BY year desc");
- // loop to create the small archive block with year/month links
- while($years = mysql_fetch_array($qy)) {
- echo('<strong><a href="'.get_year_link($years[year]).'">'.$years[year].'</a>:</strong> ');
- $qm = mysql_query("SELECT distinct month(post_date) as monthv
- FROM $tableposts
- ORDER BY monthv asc") or die(mysql_error());
- for ($i=1; $i<=12; $i++)
- {
- $q = mysql_query("SELECT *, year(post_date) as year
- FROM $tableposts
- WHERE year(post_date)='$years[year]'
- AND month(post_date)='$i'
- AND post_status='publish'
- AND post_date <= NOW()
- ORDER BY id desc") or die(mysql_error());
- $sm = $month[zeroise($i,2)]; // get the shortened month name; strtotime() localizes
- if(mysql_num_rows($q))
- { echo('<a href="'.get_month_link( $years[year], $i ).'">'.$sm.'</a> '); }
- else
- { echo('<span class="emptymonth">'.$sm.'</span> '); }
- }
- echo('<br />');
- }
- echo ('<br /><br />');
- }
- if (($format == 'both') || ($format == 'list')) { //check to see if we are supposed to display the list
- $qy = mysql_query("SELECT distinct year(post_date) as year, post_status
- FROM $tableposts
- WHERE post_status='publish'
- AND post_date <= NOW()
- ORDER BY year desc");
- // loop to display links to all posts, sorted by descending month and day
- while($years = mysql_fetch_array($qy)) {
- $qm = mysql_query("SELECT distinct month(post_date) as monthv FROM $tableposts ORDER BY monthv desc") or die(mysql_error());
- while($date = mysql_fetch_array($qm)) {
- $q = mysql_query("SELECT *, year(post_date) as year, month(post_date) as monthv
- FROM $tableposts WHERE year(post_date)='$years[year]'
- AND month(post_date)='$date[monthv]'
- AND post_status='publish'
- AND post_date <= NOW()
- ORDER BY id desc") or die(mysql_error());
- if(mysql_num_rows($q)) {
- $lm = $month[zeroise($date[monthv],2)]; // get the full month name; strtotime() localizes
- echo('<h2><a href="'.get_month_link( $years[year], $date[monthv] ).'">'.$lm.' '.$years[year].'</a></h2>');
- echo('<ul>');
- $q = mysql_query("SELECT *, year(post_date) as year, month(post_date) as monthv
- FROM $tableposts WHERE year(post_date)='$years[year]'
- AND month(post_date)='$date[monthv]'
- AND post_status='publish'
- ORDER BY post_date desc") or die(mysql_error());
- while($post = mysql_fetch_array($q)) {
- if ($post[post_date_gmt] <= $now) {
- if ($catID != '') { // check to see if a category id was specified in the arguments
- // get the categories that are attached to the current post
- $cats = $wpdb->get_col("SELECT category_id FROM $wpdb->post2cat WHERE post_id = $post[ID]");
- $found=false;
- foreach ($cats as $cat) { // look to see if the specified category is attached to the current post
- if ($cat == $catID) $found=true;
- }
- if (!$found) echo('<li><a href="'.get_permalink($post[ID]).'">'.$post[post_title].'</a></li>');
- }
- else echo('<li><a href="'.get_permalink($post[ID]).'">'.$post[post_title].'</a></li>');
- }
- }
- echo ('</ul><br />');
- }
- }
- }
- }
- }
- ?>
Written by oldmonk on 八月 19th, 2006 with
5 comments.
Read more articles on IT.
- [+] Digg: Feature this article
- [+] Del.icio.us: Bookmark this article
- [+] Furl: Bookmark this article

#1. 十二月 22nd, 2006, at 11:03 上午.
smartArchives()函数调用。,能不能具体写出来?我怎么试也不可以啊…汗
[回复此评论]