苏醒 苏醒
  • 首页
  • WP主题
  • WP插件
  • WP教程
  • 是日一记
  • 博客
    • 留言
    • 唠叨
    • 盆友圈
    • 栏目推荐

suxing

管理员
每天清晨有多少双眼睛睁开,有多少人的意识苏醒过来,便有多少个世界。
IP归属地: 广东
文章
214
评论
236
suxing
2015-02-28 2:36:25 广东

WordPress 4.1 中新增的主题函数

文章字数:1367
阅读时间: 4 分钟
智能摘要 DeepSeek
WordPress 4.1 新增了6个主题特性,包括`title-tag`、`the_archive_title()`、`the_archive_description()`、`the_post.Navigation()`、`the_posts.Navigation()`和`the_posts.pagination()`。这些特性帮助开发者简化主题功能,提升开发效率,例如`title-tag`可避免重复添加标题,`the_archive_title()`和`the_archive_description()`简化归档描述处理,而`the_post`和`the_posts`的导航特性则帮助简化模板代码。

WordPress 4.1 正式发布了,新增了不少非常实用的主题函数。

以下是各函数介绍:

[quote] title-tag[/quote]

add_theme_support( ‘title-tag’ )

在 WordPress 4.1 开始新增了一个名为 title-tag 的主题特性。

通过声明这个特性,主题就能知道自身并没有定义标题,WordPress 就可以安全的添加标题而无须担心会导致重复添加。

function theme_slug_setup() {
add_theme_support( 'title-tag' );
}
add_action( 'after_setup_theme', 'theme_slug_setup' );

[quote] the_archive_title()[/quote]

the_archive_title() / get_the_archive_title()

WordPress 的归档种类有 N 多种,日期、分类、标签、文章形式等…… 而这个不起眼的函数却可以帮你节省不少归档模板上的逻辑处理。

the_archive_title( '<h1 class="page-title">', '</h1>' );

the_archive_description() / get_the_archive_description()

[quote] 返回归档的相关描述[/quote]

和上一个函数类似,这个函数会返回归档的相关描述。

the_archive_description( '<div class="taxonomy-description">', '</div>' );

[quote] 返回当前文章的前/后导航。[/quote]

the_post_navigation() / get_the_post_navigation()

while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
the_post_navigation();
endwhile; // end of the loop.

[quote] 返回文章列表的前/后导航。[/quote]

the_posts_navigation() / get_the_posts_navigation()

if ( have_posts() ) :
 while ( have_posts() ) : the_post();
 get_template_part( 'content', get_post_format() );
 endwhile;
 the_posts_navigation();
 else :
 get_template_part( 'content', 'none' );
 endif;

[quote] 返回文章列表的分页式导航。[/quote]

the_posts_pagination() / get_the_posts_pagination()

if ( have_posts() ) :
 while ( have_posts() ) : the_post();
 get_template_part( 'content', get_post_format() );
 endwhile;
 the_posts_pagination();
 else :
 get_template_part( 'content', 'none' );
 endif;
  • WordPress 教程
  • WordPress主题函数
  • WP4.1主题函数
等 人表示很赞
7,709
1

评论 (1)

  • 苏醒 作者

    测试

    11 年前 广东省 回复 0
⚠️ 登录后可查看更多评论内容
登录
suxing
suxing
2014-07-05 13:32:45 广东

推荐 简单几步让你拥有个性化的Gravatar头像

智能摘要 DeepSeek WordPress后台无上传头像功能,可修改代码扩展。Gravatar是全球通用头像服务,用户可在官网申请头像后,将其关联邮箱,即 ...
  • WordPress 教程
  • Gravatar头像
7,794 5
suxing
suxing
2019-12-25 12:36:27 广东

推荐 双旦将至,WordPress 网站实现下雪特效,云体验下雪的赶脚

智能摘要 DeepSeek 圣诞元旦期间, WordPress 用户可以通过 nicetheme 提供的雪花特效积木轻松实现网站背景的雪花飘落效果。积木启动后 ...
  • WordPress 教程
3,682 1
suxing
suxing
2014-11-10 0:50:47 广东

推荐 WORDPRESS常用固定链接(伪静态)格式

智能摘要 DeepSeek WordPress伪静态设置可提升网站优化,固定链接可根据主机类型(Linux或Windows)进行设置。Linux下支持多种永久链接格式,包括默认自动获取文章ID、手动添加标题等。若出现404错误,可尝试恢 ...
  • WordPress 教程
14,191 3
suxing
suxing
2021-11-13 16:06:24 广东

推荐 阿里云虚拟机如何设置wordpress伪静态规则

智能摘要 DeepSeek 使用阿里云虚拟机搭建WordPress网站时,设置固定链接后可能出现404错误。解决方法是在阿里云后台的「高级环境设置」-> ...
  • WordPress 教程
3,657 1
suxing
suxing
2016-04-22 9:25:04 广东

推荐 苏醒的WordPress主题更新包安装说明

智能摘要 DeepSeek 感谢选购苏醒WP主题的正版用户!每次更新主题包都凝聚了用户建议,使主题更完善。正版用户可通过以下方式获取更新包: 1. 登录网站自行下载,避免使用迅雷等第三方工具。 2. 使用FTP工具备份旧版本,修改文件夹 ...
  • WordPress 教程
10,190 4

我用的 WordPress 主题

2021 年单栏 WordPress 主题

Copyright © 2012-2026 苏醒. All rights reserved. Designed by nicetheme.
  • 首页
  • 主题
  • 教程
  • 博客
  • 唠叨
  • 留言