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;