欢迎访问我们的网站

选择语言

  • English
  • 简体中文
  • 日本語
  • 한국어
  • Français
  • Deutsch
  • Español
  • Português
  • Italiano
  • Русский
  • العربية
  • Nederlands
  • Türkçe
  • Polski
  • Svenska
  • Dansk

WordPress系列

08文章详情调用–新手小白,快速使用静态页面建立wordpress主题

09.09.2025 25

08文章详情调用

1.文章详情调用的标签—常用的

TEXT
123456
1.1<?php the_title();  ?>//标题
1.2<?php the_content();  ?>//内容
1.3<?php the_excerpt();  ?>//摘要
1.4<?php the_permalink(); ?>//链接
1.5<?php the_ID();  ?>//文章ID
1.6<?php the_time('Y-m-d'); ?>//时间

备注:时间格式:Y-m-d属于固定格式,我们可以自己定义格式,比如:Y-m-d H:i:
也可以使用后台调用如果使用后台调用直接使用代码即可
注意,一个页面只有一个时间的显示,如果像使用多个,使用标签

TEXT
1234567891011
1.7<?php the_category();  ?>//分类
1.8<?php the_tags();  ?>//标签
1.9<?php the_author();  ?>//作者
1.10<?php the_post_thumbnail_url('full'); ?>//获取文章特色图片原图URL

1.11<?php the_post_thumbnail_url('thumbnail'); ?>//获取文章特色图片缩略图URL

1.12<?php the_post_thumbnail_url('medium'); ?>//获取文章特色图片中等尺寸URL
1.13<?php the_category(', '); ?>//显示文章所属分类(逗号分隔)
1.14<?php the_tags('标签: ', ', '); ?>//显示文章标签
1.15<?php the_permalink(); ?>//获取文章链接

2.关于文章上一篇和下一篇的调用

TEXT
1234
<!-- 上一篇 -->
<?php previous_post_link('%link', '« 上一篇: %title', true); ?>
<!-- 下一篇 -->
<?php next_post_link('%link', '下一篇: %title', true); ?>

3.评论调用

TEXT
12345
<?php if (comments_open() || get_comments_number()) : comments_template(); endif; ?>
3.1评论数调用
<?php comments_number('0 条评论', '1 条评论', '% 条评论'); ?>
3.2.评论列表
<?php if (have_comments()) : ?>

4.关于页面浏览量调用(使用WP-PostViews插件(推荐))
4.1关于文章浏览量调用

TEXT
12
<?php if(function_exists('the_views')) { the_views(); } ?>
<?php if(function_exists('the_views')) { the_views(true); } ?>

4.2关于页面浏览量调用(不使用插件,)
在主题的functions.php中添加:

TEXT
12345678
function set_post_views() {
    if (is_single()) {
        $post_id = get_the_ID();
        $count = (int)get_post_meta($post_id, 'post_views_count', true);
        update_post_meta($post_id, 'post_views_count', $count + 1);
    }
}
add_action('wp_head', 'set_post_views');

模板中调用:

TEXT
1
<?php echo get_post_meta(get_the_ID(), 'post_views_count', true) ?: 0; ?>

4.3使用第三方统计,比如谷歌,百度,CNZZ等


微信二维码
抖音二维码