修改WordPress主题文件(4)
制作index.php
将index.php改成动态页面,将里面多余无用的代码删掉,保留下来有用的:
<?php get_header(); ?>
<!-- Column 1 /Content -->
<div class="grid_8">
<!-- Blog Post -->
<div class="post">
<!-- Post Title -->
<h3 class="title"><a href="single.html">Loreum ipsium massa cras phasellus</a></h3>
<!-- Post Data -->
<p class="sub"><a href="#">News</a>, <a href="#">Products</a> • 31st Sep, 09 • <a href="#">1 Comment</a></p>
<div class="hr dotted clearfix"> </div>
<!-- Post Image -->
<img class="thumb" alt="" src="<?php bloginfo('template_url'); ?>/images/610x150.gif" />
<!-- Post Content -->
<!-- Read More Button -->
<p class="clearfix"><a href="single.html" class="button right"> Read More...</a></p>
</div>
<div class="hr clearfix"> </div>
<!-- Blog Navigation -->
<p class="clearfix"> <a href="#" class="button float"><< Previous Posts</a> <a href="#" class="button float right">Newer Posts >></a> </p>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
1.添加文章标题
接下来找到:
<h3 class="title"><a href="single.html">xxxxxxxxx</a></h3>
改成:
<h3 class="title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h3>
函数作用:
<?php the_permalink(); ?>输出文章的URL链接
<?php the_title(); ?>输出文章的标题
2.添加文章标签
找到:
<a href="#">News</a>, <a href="#">Products</a>
改成:
<?php the_tags('标签:',',',''); ?>
3.添加日期
找到日期位置
改成:
<?php the_time('Y年m月d日')?>
代码示例:
<?php the_time('Y年n月j日')?> 1999年5月1日
<?php the_time('Y年m月d日')?> 1999年05月01日
<?php the_time('Y-m-d')?> 1999-05-01
<?php the_time('y-m-d H:i:s')?> 99-05-01 02:09:08
4.显示评论数
查找代码:
<a href="#"></a>
改成:
<?php comments_popup_link('0条评论','1条评论','%条评论','','评论已关闭'); ?>
5.添加编辑按钮
功能属于可选,如需要在评论下添加代码:
<?php edit_post_link('编辑','&bull',''); ?>
6.添加文章内容
找到<!--Post Content-->
改成:
<!--Post Content-->
<?php the_content('阅读全文...'); ?>
7.阅读全文
查找:
<a href="single.html" class="button right">Read More...</a>
改成:
<a href="<?php the_permalink(); ?>" class="button right">阅读全文</a>
8.添加文章循环
查找:
<!--Blog Post-->
改成:
<!--Blog Post-->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
在查找:
<div class="hr clearfix"> </div>
改成:
<div class="hr clearfix"> </div>
<?php endwhile; ?>
在查找:
</div>
<?php get_sidebar(); ?>
改成:
<?php else : ?>
<h3 class="title"><a href="#" rel="bookmark">未找到</a></h3>
<p>没有找到任何文章!</p>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
9.添加文章分页