導讀:製作 footer 檔案上節內容我們已經弄好了部落格的頁頭 header php,今天我們就一起來製作頁尾 footer php 。 footer php 與 header php 差不多,寫這個

上節內容我們已經弄好了部落格的頁頭 header.php,今天我們就一起來製作頁尾 footer.php 。 footer.php 與 header.php 差不多,寫這個檔案的目的也是為了精簡程式碼,提高程式碼的重用性,Aurelius 主題目錄中的所有頁面的頁尾程式碼幾乎都是一樣的,我們就把這些程式碼提取出來放到 footer.php 。

在 Aurelius 主題目錄中新建檔案 footer.php,我們提取出 index.php 中的頁尾程式碼複製到 footer.php 中 (如果以後你製作自己的主題,可以根據需要決定哪些是 footer 程式碼):

<!– Footer –>
<p class=「grid_12 footer clearfix」> <span class=「float」><strong>Design By</strong> QwibbleDesigns&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>Code By</strong> <a href=「https://www.weixiaoduo.com/」>Weixiaoduo</a></span> <a class=「float right」 href=「#」>top</a> </p>
</div>
<!–end wrapper–>
</body>
</html>

再用文字編輯器開啟 index.php 、 archive.php 、 contact.php 、 full_width.php 、 page.php 和 single.php,刪掉以上類似程式碼,改成:

好,現在開啟你的部落格主頁,看看我們製作的主題是否還可以正常工作,答案是可以的,跟原來幾乎沒什麼兩樣,頁尾還是跟原來一樣。現在來新增上你的部落格版權宣告資訊和 wp_footer()函式,將 footer.php 中所有程式碼刪除,改成:

<!– Footer –>
<p class=」grid_12 footer clearfix」>
<span class=」float」> 版權所有 &copy; 2010 <?php bloginfo(『name』); ?>
&nbsp;&nbsp;|&nbsp;&nbsp;Powered By <a rel=」external」 title=」WordPress 主頁」 class=」link」 href=」http://WordPress.org/」>WordPress</a>
&nbsp;&nbsp;|&nbsp;&nbsp;Design By QwibbleDesigns&nbsp;&nbsp;|&nbsp;&nbsp;
Code By <a href=」https://www.weixiaoduo.com/」>Weixiaoduo</a>
</span>
<a class=」float right」 href=」#」>top</a> </p>
</div>
<!–end wrapper–>
<?php wp_footer(); ?>
</body>
</html>

這裡用到了我們上次學到的 bloginfo('name')函式來輸出你的部落格標題,wp_footer()wp_head()差不多,都是用於提高你的主題相容性,畢竟有很多外掛要在頁尾輸出一些東西才能正常工作。現在你的頁尾應該是有模有樣了吧:

footer.php 中加入了作者的資訊,當然包括我的資訊,如果你覺得 Code By Ludou 這幾個字特別礙眼,你可以將其刪除,但是請不要刪除設計師和 WordPress 的資訊,畢竟這是對他們最起碼的尊重!

好了,footer.php 的製作就這麼簡單。

最後提供經過本次修改後的 Aurelius 主題檔案,你可以用文字編輯器開啟看看,跟你修改的檔案比較比較,看看你改得怎麼樣?