修改Wordpress的默认日历样式
2.09, 2009
wordpress
在侧边栏里加了一个日历,用的是WordPress的默认日历插件,但样式实在是太难看了,于是就修改了日历样式
在主题的style.css中加了以下代码:
下载: wp-calendar.css
- #wp-calendar{
- border-collapse: collapse;
- border-spacing: 0;
- border: solid 1px #666699;
- }
- #wp-calendar a {
- color: #990099;
- text-decoration: none;
- }
- #wp-calendar a:hover {
- color: #FF0000;
- text-decoration: underline;
- }
- #wp-calendar #today{
- background: #FFFF33;
- }
- #wp-calendar thead{
- background: #9999CC;
- }
- #wp-calendar tfoot{
- background: #9999CC;
- }
- #wp-calendar caption{
- background: #666699;
- }
- #wp-calendar tbody{
- text-align:center;
- }
- #wp-calendar .saturday{
- color: #6666FF;
- }
- #wp-calendar .sunday{
- color: #FF6666;
- }
最后的.saturday和.sunday是为了将星期六和星期天加上颜色,这还需要修改wp-include下的general-template.php文件,所以如果不需要为星期六和星期天加颜色的话,以上的CSS代码就足够了。
以下是为了将星期六和星期天加上颜色的代码:(function get_calendar中)
打开wp-include下的general-template.php文件,找到以下代码
- 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)) )
- echo ‘<td id="today">‘;
- else
- echo ‘<td>‘;
- if ( in_array($day, $daywithpost) ) // any posts today?
- echo ‘<a href="‘ . get_day_link($thisyear, $thismonth, $day) . "\" title=\"$ak_titles_for_day[$day]\">$day</a>";
- else
- echo $day;
- echo ‘</td>‘;
将上面的代码修改为下面的样子:
- 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)) )
- echo ‘<td id="today">‘;
- else
- echo ‘<td>‘;
- // —————— 增加代码开始————————————————-
- if ( 6 == calendar_week_mod(date(‘w‘, mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) ) {
- $tmp_day = "<span class=\"saturday\">$day</span>";
- }elseif (0 == calendar_week_mod(date(‘w‘, mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins)) {
- $tmp_day = "<span class=\"sunday\">$day</span>";
- }else{
- $tmp_day = $day;
- }
- //————————-增加代码结束——————————————-
- if ( in_array($day, $daywithpost) ) // any posts today?
- echo ‘<a href="‘ . get_day_link($thisyear, $thismonth, $day) . "\" title=\"$ak_titles_for_day[$day]\">$day</a>";
- else
- echo $tmp_day; //————-修改这里———————-
- echo ‘</td>‘;
Popularity: 31% [?]
相关文章:


一月 7th, 2010 at 4:22 下午
请问你的日历是怎么在年份后面加上”年”的啊?
回复
一月 7th, 2010 at 9:31 下午
现在的状况是更新到了2.9.1时的状况,自动变成这样子了,我什么都没有顾得上改。原来改的东西也都丢掉了。
回复