今天我们来制作单文章页single.PHP,有了之前制作index.PHP的经验,制作single.PHP也不再那么难了,这里将直接略过一些内容,直接给出结果。如果对某些修改不太清楚,可以先参考:wordpress主题制作全过程(八):制作index.PHP
<h3 class="title"><a href="single.html">Loreum ipsium massa cras phasellus</a></h3>
改成:
<a href="#">News</a>,<a href="#">Products</a>
改成:
3、添加日期
找到:31st Sep,09 改成:
<?PHP the_time('Y年n月j日') ?>
<a href="#">7 Comments</a>
改成:
6、添加文章内容
将<!-- Post Content --> 和 <!-- Post Links -->之间的代码全部删除,替换成:
<?PHP the_content(); ?>
<img class="thumb" src="<?PHP bloginfo('template_url'); ?>/images/610x150.gif" alt=""/>
7、添加返回博客首页和发表评论按钮
其实就是添加博客首页和评论锚点链接,在制作header.PHP,我们已经知道可以通过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" >发表评论</a> </p>
好了,基本上的修改就这些了,但是你的文章页仍然不能显示文章内容,你得给它加上一个条件语句,这样wordpress才会去数据库读出你的文章内容。搜索代码:<!-- Column 1 /Content -->
改成:
<!-- Column 1 /Content -->
<?PHP if (have_posts()) : the_post(); update_post_caches($posts); ?>
<?PHP if (have_posts()) : the_post(); update_post_caches($posts); ?>
将:
</div>
<?PHP get_sidebar(); ?>
<?PHP get_sidebar(); ?>
改成:
现在你的文章内容应该都可以正常显示了,一个文章页基本上也成型了。下节我们将讲解如何制作评论页,本次不提供修改的主题文件下载,下次一起提供。
Our blog,keeping you up-to-date on our latest news.
<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>
<div class="hr grid_12 clearfix"> </div>
好了今天的教程就讲到这。