Thu 28 Dec 2006
Posted in Wordpress by 工頭 ,528 Views
當我們在使用wordpress 的顯示留言功能時,長時間發覺會因為留言的增加而會有一直不斷的增長頁面,所以去限定留言的顯示數目才能讓留言板頁面不致於太長,當然這種小小的功能就不必去加一些有的沒的的 plugin 了。
修改 comments.php 此檔案.用UTF-8文字編輯器或 vi 將下列檔案打開
/var/www/html/wp/wp-content/themes/mistylook2/comments.php
在大約第28行的地方,修改下面的程式碼︰
〈?php foreach ($comments as $comment) : ?〉
〈?php $commentcounter++; ?〉
〈li class=”〈?php echo $oddcomment; ?〉” id=”comment-〈?php comment_ID() ?〉”〉
改成
〈?php foreach ($comments as $comment) : ?〉
〈?php $commentcounter++; ?〉
〈?php if ($commentcounter > 15) break;?〉
〈li class=”〈?php echo $oddcomment; ?〉” id=”comment-〈?php comment_ID() ?〉”〉
這樣修改後存檔就大功告成了。
其中那 15 數字,可以更改成您要顯示出多少個留言數目。
Comments Off
Mon 25 Dec 2006
Posted in Wordpress by 工頭 ,689 Views
原本 wordpress 預設的顯示每一筆留言的背景顏色都是同一個顏色的,但是看久了就有一點單調,所以就動起了修改的念頭,但是我又不想加 plugin,那就只好在程式碼中尋找是否有可以動手之處,找了一下就發現其實並不難。依下列方式去修改 wordpress 中 theme 就會將 wordpress 的顯示留言的背景顏色改為兩種顏色交替顯示。(在這裏以 mistylook2 這個 theme 來示範。)
若要設定此一功能,就要修改 style.css 此檔案.用UTF-8文字編輯器或 vi 將下列檔案打開
/var/www/html/wp/wp-content/themes/mistylook2/style.css
在大約第386行的地方,加入下面的程式碼︰
.commentlist li.alt2
{
background:#E7EBDE;
}
之後,再修改 comments.php 此檔案.用UTF-8文字編輯器或 vi 將下列檔案打開
/var/www/html/wp/wp-content/themes/mistylook2/comments.php
在大約第386行的地方,加入下面的程式碼︰
if (’alt’ == $oddcomment) $oddcomment = ”;
else $oddcomment = ‘alt’;
改成
if (’alt’ == $oddcomment) $oddcomment = ‘alt2′;
else $oddcomment = ‘alt’;
這樣修改後存檔就大功告成了。
Comments Off
Sun 17 Dec 2006
Posted in Wordpress by 工頭 ,1,279 Views
要將 wordpress 每篇文章的標題前加上一個日曆來表示日期的話可以在 index.php 及 single.php 及 archive.php這三個檔案中加以修改,以工頭所使用的 theme為例則要作以下的修改︰
〈div class=”posttitle”〉
〈h2〉〈a xhref=”〈?php the_permalink() ?〉” rel=”bookmark” title=”Permanent Link to 〈?php the_title(); ?〉”〉〈?php the_title(); ?〉〈/a〉〈/h2〉
〈p class=”post-info”〉〈?php the_time(’F jS, Y’) ?〉 by 〈?php the_author_posts_link() ?〉 〈/p〉
〈/div〉
改成
〈div class=”posttitle”〉
〈p class=”post-date”〉〈?php the_time(’D j M Y’); ?〉〈/p〉〈h2〉〈a xhref=”〈?php the_permalink() ?〉” rel=”bookmark” title=”Permanent Link to 〈?php the_title(); ?〉”〉〈?php the_title(); ?〉〈/a〉〈/h2〉
〈p class=”postmetadata”〉Posted in 〈?php the_category(’, ‘) ?〉 by 〈?php the_author_posts_link() ?〉 〈/p〉
〈/div〉
再將下列文字加入 style.css 文字檔尾端。
.post-date {
float: left;
color: #333;
font-family: Georgia,’Lucida sans ms’, Verdana, Arial, Helvetica, sans-serif;
font-size: 0.9em;
text-align: center;
font-weight: bold;
margin: 3px 10px 0 0;
padding: 8px 3px;
width: 48px;
background: #E7EBDE;
line-height:1em;
}
如此就可以逹到將 wordpress 每篇文章的標題前加上一個日曆來表示日期的功能了。
Comments Off
Thu 14 Dec 2006
Posted in Wordpress by 工頭 ,717 Views
如果在 wordpress 加上一個小月曆,但又不滿意那預設的月曆(別看那個不起眼的小月曆,有時候它可是驅動我寫文章的主要動力)。依下列方式去修改 wordpress 中 theme 就會得到一個很像 b2evolution 預設的小月曆。
先將下列文字加入 sidebar.php 文字檔中。
〈?php get_calendar(); ?〉
再將下列文字加入 style.css 文字檔尾端。
#wp-calendar {
background: #fff;
border: 1px solid #ddd;
empty-cells: show;
font-size: 14px;
width: 10.5em;
}
#wp-calendar #next a {
padding-right: 10px;
text-align: right;
border: 1px solid #ddd;
}
#wp-calendar #prev a {
padding-left: 10px;
text-align: left;
border: 1px solid #ddd;
}
#wp-calendar a {
display: block;
text-decoration: none;
}
#wp-calendar a:hover {
color: #333;
}
#wp-calendar caption {
font-size: .8em;
font-weight: bold;
text-align: left;
padding-bottom: 0.25em;
padding-top: 0em;
text-align: center;
border: 1px solid #ddd;
}
#wp-calendar td {
color: #999;
font: normal 11px Verdana, Geneva, sans-serif;
padding: 1px 1px;
text-align: center;
}
/* Doesn’t work in IE */
#wp-calendar td.pad:hover {
background-color: #eadfdf;
}
#wp-calendar #today {
font-weight: bold;
border: 1px solid #666;
}
#wp-calendar th {
color: #003399;
font-style: normal;
text-transform: capitalize;
text-align: center;
}
Comments Off
Wed 13 Dec 2006
Posted in Wordpress by 工頭 ,1,373 Views
當我們在使用 wordpress 的留言功能時會發現最新的留言永遠在最後一筆,若是留言只有幾筆則還可以接受,但若是有數十筆留言的話則要找了半天才會發現最新的留言在數頁之後了。所以將 wordpress 的留言排序改為最新留言為第一筆留言應該是比較好的作法吧!
若要設定此一功能,就要修改comment-functions.php此檔案.用UTF-8文字編輯器或 vi 將下列檔案打開
/var/www/html/wp/wp-includes/comment-functions.php
在第44行及第48行找到下列文字,去修改此文字檔的內容.
ORDER BY comment_date
改成
ORDER BY comment_date DESC
存檔後,就可以將 wordpress 的留言排序改為最新留言為第一筆留言。
Comments Off