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

suxing

管理员
每天清晨有多少双眼睛睁开,有多少人的意识苏醒过来,便有多少个世界。
IP归属地: 广东
文章
216
评论
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,993
1

评论 (1)

  • 苏醒 作者

    测试

    11 年前 广东省 回复 0
⚠️ 登录后可查看更多评论内容
登录
suxing
suxing
2019-01-05 10:36:25 广东

推荐 WordPress标题的分隔符-被转义为&#8211的解决办法

智能摘要 DeepSeek 在WordPress中,使用英文横杠“-”作为SEO分隔符时,会被wptexturize函数转义为HTML字符。为解决此问题,可停 ...
  • WordPress 教程
  • amp
  • wordpress
  • wptexturize
8,306 6
suxing
suxing
2015-12-30 11:49:08 广东

推荐 关于WordPress后台加载速度慢的问题

智能摘要 DeepSeek 该问题主要因谷歌字体和头像加载问题导致,具体解决方案如下: 1. 禁止加载谷歌字体:在`functions_suxingme.php`或`add.php`中添加以下代码: “`php add_filter( ...
  • WordPress 教程
  • Gravatar头像
  • Gravatar头像无法显示
  • wordpress主题
  • wordpress教程
8,357 0
suxing
suxing
2014-11-26 14:11:52 广东

推荐 如何修改wordpress主题的样式和文件

智能摘要 DeepSeek 这篇文章介绍了如何通过浏览器检查元素、使用notepad++修改CSS代码等方法,帮助用户在WordPress主题中调整样式。具体步骤包括:1)下载并解压主题文件,2)使用浏览器检查目标元素,3)在notep ...
  • WordPress 教程
18,728 5
suxing
suxing
2017-06-29 14:23:29 广东

推荐 WordPress上传的文件尺寸超过php.ini中定义的upload_max_filesize值解决方法

智能摘要 DeepSeek WordPress上传主题包时,若提示文件尺寸超过upload_max_filesize限制,需修改php.ini中的upload_max_filesize和post_max_size参数(默认2MB),建议 ...
  • WordPress 教程
13,902 0
suxing
suxing
2019-08-04 23:58:25 广东

推荐 WordPress主题/插件升级,一直提示:正在执行例行维护,请一分钟后回来

智能摘要 DeepSeek 当WordPress升级失败或加载缓慢时,可能会出现维护模式提示。原因可能是网络问题导致升级失败。解决方法是使用FTP或SSH工具 ...
  • WordPress 教程
  • wordpress
  • 升级
  • 插件
4,623 1

我用的 WordPress 主题

2021 年单栏 WordPress 主题

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