天天看點

制作wordpress留言闆

總結步驟如下:

1.找到模闆目錄中的single.php檔案,複制single.php并重命名為guestbook.php

2.在guestbook最頂部添加如下代碼(用于模闆調用)

<?php
/*
Template Name: Guestbook
*/
?>      

3.進入部落格管理背景,點撰寫頁面,在“頁面模闆”處選擇第二步弄好的“Guestbook”,發表一個頁面,然後打開這個頁面并記錄頁面連結位址(第9步要用)

4.優化guestbook.php把日志發表時間、标簽什麼的删掉

日志發表時間:

Posted in<?phpthe_category(\', \')?>on<?phpthe_time(\'m/d/Yh:ia\')?>by<?phpthe_author()?>

标簽:

<ulclass="post_tags"><liclass="tags">

<?phpthe_tags(\'Tags:\', \', \', \'\');?>&nbsp;

</li></ul>

5.替換guestbook.php中的如下代碼,使其調用新的評論頁

<?phpcomments_template();?>

替換成

<?phpcomments_template(\'/guestcomments.php\');?>

6.找到模闆目錄中的comment.php檔案,複制comment.php并重命名為guestcomments.php

7.優化guestcomments.php把“評論”都改成“留言”

8.更改留言的顯示順序,讓最新釋出的留言位于最上邊。替換guestcomments.php的如下代碼

foreach($commentsas$comment)

替換成

foreach(array_reverse($comments)as$comment)

9.更改側欄wp-includeswidgets.php,在裡邊加上“留言”的連結(非必要步驟,可省略)

<?php echo $before_widget;?>
<?php echo $before_title.$title.$after_title;?>
<ul>
<?php wp_register();?>
<li><?php wp_loginout();?></li>
<li><a href="/?page_id=2675">留言</a></li>
<li><a href="<?php bloginfo(\'rss2_url\');?>" title="<?php echoattribute_escape(__(\'Syndicate this site using RSS 2.0\'));?>"><?php_e(\'Entries <abbr title="Really Simple Syndication">RSS</abbr>\');?></a></li>
<li><a href="<?php bloginfo(\'comments_rss2_url\');?>" title="<?php echoattribute_escape(__(\'The latest comments to all posts in RSS\'));?>"><?php_e(\'Comments <abbr title="Really Simple Syndication">RSS</abbr>\');?></a></li>
<?php wp_meta();?>
</ul>
<?php echo$after_widget;?>      

備注:本步驟如果出現亂碼的情況,解決方法如下

A.用dreamweaver打開widgets.php

B.修改-頁面屬性-标題/編碼

C.編碼-Unicode (UTF-8)-重新載入