今天我們來制作單文章頁single.php,有了之前制作index.php的經(jīng)驗,制作single.php也不再那么難了,這里將直接略過一些內(nèi)容,直接給出結(jié)果。如果對某些修改不太清楚,可以先參考:WordPress主題制作全過程(八):制作index.php
php入門到就業(yè)線上教程:進入學習
1、添加文章標題:
<h3 class="title"><a href="single.html">Loreum ipsium massa cras phasellus</a></h3>
登錄后復制
改成:
<h3 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
登錄后復制
2、添加文章標簽
<a href="#">News</a>, <a href="#">Products</a>
登錄后復制
改成:
<?php the_tags('標簽:', ', ', ''); ?>
登錄后復制
3、添加日期
找到:31st Sep, 09 改成:
<?php the_time('Y年n月j日') ?>
登錄后復制
4、顯示評論數(shù)
<a href="#">7 Comments</a>
登錄后復制
改成:
<?php comments_popup_link('0 條評論', '1 條評論', '% 條評論', '', '評論已關(guān)閉'); ?>
登錄后復制
5、添加編輯按鈕
接上面的評論代碼,改成:
<?php comments_popup_link('0 條評論', '1 條評論', '% 條評論', '', '評論已關(guān)閉'); ?><?php edit_post_link('編輯', ' ? ', ''); ?>
登錄后復制
6、添加文章內(nèi)容
將<!– Post Content –> 和 <!– Post Links –>之間的代碼全部刪除,替換成:
<?php the_content(); ?>
登錄后復制
另外,你可以將文章頁那張圖片刪除了,刪除以下代碼:
<img class="thumb" src="<?php bloginfo('template_url'); ?>/images/610x150.gif" alt=""/>
登錄后復制
7、添加返回博客首頁和發(fā)表評論按鈕
其實就是添加博客首頁和評論錨點鏈接,在制作header.php,我們已經(jīng)知道可以通過get_option('home');來獲取博客地址。
<p class="clearfix"> <a href="blog.html" class="button float" ><< Back to Blog</a> <a href="#commentform" class="button float right" >Discuss this post</a> </p>
登錄后復制
改成:
<p class="clearfix"> <a href="<?php echo get_option('home'); ?>" class="button float" ><< 返回首頁</a> <a href="#commentform" class="button float right" >發(fā)表評論</a> </p>
登錄后復制
好了,基本上的修改就這些了,但是你的文章頁仍然不能顯示文章內(nèi)容,你得給它加上一個條件語句,這樣WordPress才會去數(shù)據(jù)庫讀出你的文章內(nèi)容。搜索代碼:<!– Column 1 /Content –>
改成:
<!-- Column 1 /Content --> <?php if (have_posts()) : the_post(); update_post_caches($posts); ?>
登錄后復制
將:
</div> <?php get_sidebar(); ?>
登錄后復制
改成:
</div> <?php else : ?> <div class="errorbox"> 沒有文章! </div> <?php endif; ?> <?php get_sidebar(); ?>
登錄后復制
現(xiàn)在你的文章內(nèi)容應(yīng)該都可以正常顯示了,一個文章頁基本上也成型了。下節(jié)我們將講解如何制作評論頁,本次不提供修改的主題文件下載,下次一起提供。
另外,文章頁頂部會有一段文字:
Our blog, keeping you up-to-date on our latest news.
登錄后復制
可以替換成你的內(nèi)容。如果不需要,可以將以下代碼刪除:
<h2 class="grid_12 caption clearfix">Our <span>blog</span>, keeping you up-to-date on our latest news.</h2> <div class="hr grid_12 clearfix"> </div>
登錄后復制
推薦學習:《WordPress教程》