苏醒 苏醒
  • 首页
  • WP主题
  • WP插件
  • WP教程
  • 是日一记
  • 博客
    • 留言
    • 唠叨
    • 友情链接
首页 WordPress 教程 WordPress 4.1 中新增的主题函数

WordPress 4.1 中新增的主题函数

suxing 2015-02-28 2:36:25

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主题函数# WP4.1主题函数
0

评论 (1)

返回
  • 苏醒

    测试

    8年前 广东省 回复

猜你喜欢

  • 阿里云虚拟机如何设置wordpress伪静态规则
  • 阿里云 CDN 跨域问题: No 'Access-Control-Allow-Origin' header is present on the requested resource
  • WordPress 小Tips:如何不显示站点顶部工具栏
  • PHP 错误 Parse error: syntax error, unexpected '?' 解决办法
  • WordPress 建立数据库连接时出错
suxing
每天清晨有多少双眼睛睁开,有多少人的意识苏醒过来,便有多少个世界。
197
文章
289
评论
306
获赞
suxing

我用的 WordPress 主题

2021 年单栏 WordPress 主题

  • 首页
  • WP主题
  • WP插件
  • WP教程
  • 是日一记
  • 博客
Copyright © 2012-2023 苏醒. Designed by nicetheme.
  • 首页
  • 主题
  • 教程
  • 博客
  • 唠叨
  • 留言
  • 是日一记