‘wordpress’ 分类所有文章

修改Wordpress的默认日历样式

在侧边栏里加了一个日历,用的是WordPress的默认日历插件,但样式实在是太难看了,于是就修改了日历样式

在主题的style.css中加了以下代码:

  1. #wp-calendar{ 
  2.   border-collapse: collapse;
  3.   border-spacing: 0;
  4.   border: solid 1px #666699;
  5. }
  6. #wp-calendar a { 
  7.   color: #990099;
  8.   text-decoration: none;
  9. }
  10.  
  11. #wp-calendar a:hover {
  12.   color: #FF0000;
  13.   text-decoration: underline;
  14. }
  15.  
  16. #wp-calendar #today{ 
  17.    background: #FFFF33;
  18.  }
  19. #wp-calendar thead{ 
  20.    background: #9999CC;
  21.  }
  22. #wp-calendar tfoot{ 
  23.    background: #9999CC;
  24.  }
  25. #wp-calendar caption{ 
  26.    background: #666699;
  27.  }
  28. #wp-calendar tbody{ 
  29.   text-align:center;
  30.  } 
  31.  
  32. #wp-calendar .saturday{ 
  33.   color: #6666FF;
  34.  }
  35.  
  36. #wp-calendar .sunday{ 
  37.   color: #FF6666;
  38.  }

最后的.saturday和.sunday是为了将星期六和星期天加上颜色,这还需要修改wp-include下的general-template.php文件,所以如果不需要为星期六和星期天加颜色的话,以上的CSS代码就足够了。

以下是为了将星期六和星期天加上颜色的代码:(function get_calendar中)
打开wp-include下的general-template.php文件,找到以下代码

  1. if ( $day == gmdate(j, (time() + (get_option(gmt_offset) * 3600))) && $thismonth == gmdate(m, time()+(get_option(gmt_offset) * 3600)) && $thisyear == gmdate(Y, time()+(get_option(gmt_offset) * 3600)) )
  2.             echo <td id="today">;
  3.         else
  4.             echo <td>;
  5.         if ( in_array($day, $daywithpost) ) // any posts today?
  6.                 echo <a href=" . get_day_link($thisyear, $thismonth, $day) . "\" title=\"$ak_titles_for_day[$day]\">$day</a>";
  7.         else
  8.             echo $day;
  9.         echo </td>;

将上面的代码修改为下面的样子:

  1. if ( $day == gmdate(j, (time() + (get_option(gmt_offset) * 3600))) && $thismonth == gmdate(m, time()+(get_option(gmt_offset) * 3600)) && $thisyear == gmdate(Y, time()+(get_option(gmt_offset) * 3600)) )
  2.             echo <td id="today">;
  3.         else
  4.             echo <td>;
  5. // ——————  增加代码开始————————————————-
  6.    if ( 6 == calendar_week_mod(date(w, mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) ) { 
  7.    $tmp_day = "<span class=\"saturday\">$day</span>";
  8.     }elseif (0 == calendar_week_mod(date(w, mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins)) { 
  9.        $tmp_day = "<span class=\"sunday\">$day</span>";
  10.    }else{ 
  11.         $tmp_day = $day;
  12.    }
  13.  
  14. //————————-增加代码结束——————————————-
  15.         if ( in_array($day, $daywithpost) ) // any posts today?
  16.                 echo <a href=" . get_day_link($thisyear, $thismonth, $day) . "\" title=\"$ak_titles_for_day[$day]\">$day</a>";
  17.         else
  18.             echo $tmp_day//————-修改这里———————-
  19.         echo </td>;

Popularity: 31% [?]

给Wordpress添加统计数据

孜妈看见别人博客中有显示的流量统计,强烈要求孜孜成长日记上也加上。应孜妈的要求,为孜孜成长日记的边栏上加上了网站统计数据。

实现这个功能,用到了FireStatsGeneralStats两个插件,FireStats是为了实现访客统计,GeneralStats是为了统计网站的文章,留言等的数量。

插件的安装都很简单,将插件目录放到Wordpress的wp-content/plugins下然后激活插件就可以了。

为了用列表显示文章数,留言数,需要在后台管理-设置-GeneralStats中设置一下GeneralStats的格式,

首先从avialable tags中将posts和commends拖到上面的Taken Tags中,并分别设置表示名为“文章总数”和“留言总数”
general-stats1

然后在设置CSS-Tags中before-tags为“<li>”, after-details为”</li>”
general-stats2

最后在你的侧边栏(sidebar.php)中增加一个网站统计栏目。主题不同增加的方法也不相同,孜孜成长日记的侧边栏是这样的。

  1. <div class="widget widget_links">
  2. <h2>网站统计</h2>
  3. <ul>
  4.  
  5. <?php GeneralStatsComplete(); ?>
  6. <?php
  7. if (defined(FS_API))
  8. {
  9.     echo "<li> 累计流量: ".fs_api_get_page_views()."</li>";
  10.     echo "<li> 今日流量: ".fs_api_get_page_views(1)."</li>";
  11.     echo "<li> 累计访客: ".fs_api_get_visits()."</li>";
  12.     echo "<li> 今日访客: ".fs_api_get_visits(1)."</li>";
  13.   
  14. }
  15. ?>
  16.  
  17. </ul>
  18. </div>

这样就完成了。

Popularity: 41% [?]