四、wordpress内容页模板主题开发(文章页)调用标签
调用标签
<?php the_title(); ?> 1、标题文章内容页调用标签
<?php the_excerpt(); ?> 2、简介文章调用标签
<? the_post_thumbnail(); ?> 3、缩略图文章页(特色图片)调用标签 方法一
<?php the_author(); ?> 4、作者文章页调用标签
<?php the_time('y-m-d H:i:s') ?> 5、发布时间文章也调用标签
<?php the_content(""); ?> 6、文章内容文章页调用标签
<?php the_permalink();?> 7、当前文章页链接地址
<? get_the_id() ?> 8、当前文章页ID
<?php foreach((get_the_category()) as $category){echo $category->cat_name;}?> 9、当前文章所属分类栏目名
<?php foreach((get_the_category()) as $category){echo get_category_link($category);}?> 10、当前文章所属分类栏目链接
<? previous_post_link('上一篇: %link'); ?> <? next_post_link('下一篇: %link'); ?> 11、上一篇、下一篇调用
<?php comments_popup_link('0 条评论', '1 条评论', '% 条评论', '', '评论已关闭'); ?> 12、输出评论数
<?php echo get_avatar( get_the_author_email(), 36 ); ?> 13、调用作者头像
<img src="<?php $full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full'); echo $full_image_url[0]; ?>" alt="" /> 3、特色图片调用标签方法二,只调用图片地址链接
wordpress上一篇下一篇案例
<div class="next">
<div class="shang"><?php if (get_previous_post()) { previous_post_link('上一条: %link');} else {echo "没有了,已经是最后文章";} ?></div>
<div class="xia"><?php if (get_next_post()) { next_post_link('下一条: %link');} else {echo "没有了,已经是最新文章";} ?></div>
</div>
2、wordpress文章内容页面包屑调用标签,同上述列表页调用标签相同
3、文章内容single.php页面,根据文章所属不同分类选择不同的文章页模板(注:新创建content.php为文章默认页面,比如新闻栏目别名为new,新闻文章页为 content-new.php 如果没有该页面就自动调用默认content.php为文章页)
3.1、不同分类下的文章调用不同模板
<? the_post();
//获取当前文章id
$cat=get_the_category(get_the_id());
//获取当前文章分类
$name=$cat[0]->slug;
//加载content-$name.php 指定模板文件不存在 就调用默认文章模板content.php
get_template_part( 'content', $name )
?>