WordPress页面教程:单页(single.php)
一、页面简介
single.php用于显示文章的页面(相当于细节页),可以查看文章的标题,文章的内容,文章的时间,文章的作者,文章的图片。
二、页面参数
- get_header()
- have_posts()
- the_post()
- the_ID()
- the_permalink()
- the_content()
- link_pages()
- the_category()
- the_author()
- edit_post_link()
- comments_template()
- previous_post_link()
- next_post_link()
- _e()
- get_sidebar()
- get_footer()
- post_class()
- the_date()
- get_the_tags()
- the_tags()
- function_exists()
- the_views()
- get_template_part()
- wp_tag_cloud()
- get_avatar()
三、页面案例
(一)、案例1
<?php get_header();?>
<div id="container">
<?php if(have_posts()):?>
<?php while(have_posts()):the_post();?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink();?>" title="<?php the_title(); ?>"><?php the_title();?></a></h2>
<div class="entry">
<?php the_content();?>
<?php link_pages('<p><strong>Pages:</strong>', '</p>', 'number'); ?>
<p class="postmetadata">
<?php _e('分类:'); ?>
<?php the_category(',') ?> <?php _e('作者:'); ?>
<?php the_author(); ?>
<?php edit_post_link('编辑', ' | ', ''); ?>
</p>
</div>
<div class="comments-template">
<?php comments_template(); ?>
</div>
</div>
<?php endwhile;?>
<div class="navigation">
<?php previous_post_link('%link') ?> <?php next_post_link('%link') ?>
</div>
<?php else : ?>
<div class="post">
<h2><?php _e('Not Found');?></h2>
</div>
<?php endif;?>
</div>
<?php get_sidebar();?>
<?php get_footer();?>
(二)、案例2
<?php get_header(); ?>
<div id="wrap">
<div id="main">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<div class="post-meta">发表于:<?php the_date(); ?> | <?php if(get_the_tags($post->ID)) : ?>标签: <?php the_tags(__(' '), ' '); ?> |<?php endif;?> <?php if(function_exists('the_views')) the_views();?></div>
<?php the_content(); ?>
</div>
<?php comments_template(); ?>
<?php endwhile; endif; ?>
</div>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
(三)、案例3
<?php get_header(); ?>
<!-- <div class="more"><b>标签:</b><?php wp_tag_cloud('unit=px&smallest=12&largest=12&number=25&separator=, '); ?></div>
<div class="clear"></div>
</div>
<div class="space"></div> -->
<div class="content">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="lists">
<div class="lists_l"><?php echo get_avatar( get_the_author_email(), 48 ); ?></div>
<div class="lists_m">
<div class="box2">
<div class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('猛击查看 %s 的详细内容', 'kubrick'), the_title_attribute('echo=0')); ?>"><b><?php the_title(); ?></b></a></div>
<div class="read_total2"><div class="span"><?php the_author() ?>发表于<?php the_time(__('Y/m/d')) ?> 131231<?php if(function_exists('the_views')) { the_views(); } ?> <?php the_tags(); ?> <?php edit_post_link(编辑, '','»'); ?>
</div>
</div>
</div>
<div class="lists_r2">
<span><?php the_category(',') ?></span><span><a href="<?php the_permalink(); ?>#pll-comment-here" target=_blank><?php comments_number('0个评论', '1个评论', '%个评论'); ?></a>
</span>
</div>
</div>
<div style="clear:both"></div>
</div>
<div class="post_content">
<?php the_content(); ?>
</div>
<div class="post_rss">
<?php if (('open' == $post-> comment_status) && ('open' == $post->ping_status)) {
// Both Comments and Pings are open ?>
你可以<a href="#respond">发表评论</a>、<a href="<?php trackback_url(); ?>" rel="trackback">引用</a>到你的网站或博客,或通过<?php post_comments_feed_link('RSS 2.0'); ?>订阅这个日志的所有评论。
<?php } elseif (!('open' == $post-> comment_status) && ('open' == $post->ping_status)) {
// Only Pings are Open ?>
留言已关闭,但你可以将这个日志<a href="<?php trackback_url(); ?> " rel="trackback">引用</a>到你的网站或博客。
<?php } elseif (('open' == $post-> comment_status) && !('open' == $post->ping_status)) {
// Comments are open, Pings are not ?>
通告目前不可用,你可以至底部留下评论。
<?php } elseif (!('open' == $post-> comment_status) && !('open' == $post->ping_status)) {
// Neither Comments, nor Pings are open ?>
评论已关闭。
<?php } ?>
</div>
<div class="post_nav">
<div><?php previous_post_link('<b>上一篇:</b>%link') ?></div>
<div><?php next_post_link('<b>下一篇:</b>%link') ?></div>
</div>
<div class="space"></div>
<?php comments_template(); ?>
<?php endwhile; ?>
<?php else : ?>
<p class="center">哦,你找的文章好像不在哦。</p>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
<div class="clear"></div>
<div class="space"></div><div class="space"></div>
<?php get_footer(); ?>
(四)、案例4
<?php guimeng_set_post_views(get_the_ID()); ?>
<div class="content">
<article <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h2 class="title"><a class="slow" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a><span class="edit"><?php edit_post_link();?></span></h2>
<ul class="text">
<?php the_content(); ?>
<?php if(is_single){ ?><p class="zhuanzai">转载请注明:<a href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?></a> » <a href="<?php the_permalink() ?>"><?php the_title(); ?></a></p><?php } ?>
<div class="post-like">
<a href="javascript:;" data-action="ding" data-id="<?php the_ID(); ?>" class="favorite<?php if(isset($_COOKIE['bigfa_ding_'.$post->ID])) echo ' done';?>">喜欢 <span class="count">
<?php if( get_post_meta($post->ID,'bigfa_ding',true) ){
echo get_post_meta($post->ID,'bigfa_ding',true);
} else {
echo '0';
}?></span>
</a>
</div>
</ul>
<div class="textfoot">
<span><?php the_tags('标签:', ', ', ''); ?></span><span>分类:<?php the_category(', ');?></span>
</div>
</article>
</div>
THE END