【架構篇】WordPress佈景主題製作【single.php】

【架構篇】WordPress佈景主題製作【single.php】

本篇要來介紹製作WordPress佈景主題之一的single.php檔案,single.php主要用於顯示文章完整內容,比如說大標題、文字及圖片、以及像是留言、相關文章特殊功能…等等,single.php裡面的內容除了自己文章的內容之外其餘取決於自己的設計,因為是秀出完整內容的關係,所以對於WordPress來說也是非常重要的檔案之一。

秀出單篇文章內容

像之前 index.php 作法一樣,先取得之前 header.php、footer.php、sidebar.php 短碼語法引用到 single.php。

<?php get_header(); ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

取得文章標題。

<?php the_title(); ?>

接下來使用 while 循環來秀出接下來的顯示項目,the_content() 則是秀出單篇(這篇)文章內容,最後在 endwhile 結束循環。

<?php while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>

完整語法結構:

<?php get_header(); ?>
<?php the_title(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

關於WordPress系列文章事項
文章版本:
第 2.0 版本,WordPress 系列教學純屬個人經驗,若有錯誤會重新修正並加上版本號碼,目前會持續調整樣式、整理佈景語法,目前版本已調整為先教學基本架構再教學設計樣式,之後會以最終版本告知。

相關文章
作者簡介
個人頭像照片
努力寫文中!