这里首先需要创建一个文件
single.php
这个文件作为文章模版页。由wordpress规定命名。
在这个文件中必须有the_post();
将文章内容写入缓存,然后为后面的调用做准备。然后在通过the_permalink();
等方法来显示信息。
这里还需要学习如何显示上一篇文章和下一篇文章,wordpress内置了2个方法可以做到这样的效果
previous_post_link();
作用:上一篇文章链接。next_post_link();
作用:下一篇文章链接。- 这2个方法还可以自定义输出的样式。比如:
previous_post_link('上一篇:%link');
和next_post_link('下一篇:%link');
single.php文件:
<?php get_header(); ?>
<div id="left-box">
<div id="home-loop">
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" />
<?php
//获取下一篇文章的信息,并将信息存入全局变量%post中
the_post();
?>
<div class="post-item">
<div class="post-meta">
<span ><?php the_category(','); ?></span>
<span ><?php the_author(); ?></span>
<span ><?php the_time('Y-m-d'); ?></span>
<span ><?php edit_post_link('编辑'); ?></span>
</div>
<div class="post-title">
<a href="<?php the_permalink(); ?>">
<h2><?php the_title(); ?></h2>
</a>
</div>
<div class="post-content">
<?php the_content(); ?>
</div>
</div>
<div class="post-nav">
<?php
previous_post_link('上一篇:%link');
next_post_link('下一篇:%link');
?>
</div>
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>