WordPress 4.1 中新增的主题函数

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

以下是各函数介绍:

title-tag

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' );

the_archive_title()

the_archive_title() / get_the_archive_title()

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

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

返回归档的相关描述

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

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

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

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.

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

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;

返回文章列表的分页式导航。

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的默认接口路由改掉,愿意是默认的带一个 wp...
wordpress自定义分类法之后,我看到链接都自动在后面添加了一...
事情是这样的,我用 get_post_type 函数创建了一个自定义分类...
最近网站莫名其妙的被顶上了,过一个多小时,就注册一个账号...
最近服务器要到期了,就想着把网站转移到另外一台服务器,本...
今天在写wordpress的接口,然后碰到个奇怪的问题,怎么访问都...