WordPress 4.1 新增函数

最近正忙于新主题的制作,转篇关于WordPress 4.1 新增函数的文章,方便制作新版主题时参考之用。

另外,透露一下新主题的制作情况,本来准备在Ality主题的基础上修改,但心血来潮居然完全重新制作了一款主题,与Ality主题对比,主要的区别就是,重写顶部响应式固定导航菜单,放大缩略图并占据文章列表左侧,将文章标题及摘要整体移到右侧,并在手机小屏设备上隐藏文章摘要….新版主题基础结构取自WordPress 4.1 默认主题twentyfifteen,近日会启用新版主题进行测试,之后着手制作CMS布局。

在查询the_posts_pagination函数时搜到下文,用于调用WordPress内置的类似pagenavi分页式导航功能 。

add_theme_support( \’title-tag\’ )

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

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

  1.  theme_slug_setup() {
  2.    add_theme_support( \’title-tag\’ );
  3. }
  4. add_action( \’after_setup_theme\’, \’theme_slug_setup\’ );

the_archive_title() / get_the_archive_title()

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

  1. the_archive_title( \'<h1 =>\’, \'</h1>\’ );

the_archive_description() / get_the_archive_description()

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

  1. the_archive_description( \'<div =>\’, \'</div>\’ );

PS: 此函数不会返回作者描述

the_post_navigation() / get_the_post_navigation()

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

  1.  ( have_posts() ) : the_post();
  2.     get_template_part( \’content\’, get_post_format() );
  3.     the_post_navigation();

the_posts_navigation() / get_the_posts_navigation()

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

  1.  ( have_posts() ) :
  2.      ( have_posts() ) : the_post();
  3.         get_template_part( \’content\’, get_post_format() );
  4.     ;
  5.     the_posts_navigation();
  6.  :
  7.     get_template_part( \’content\’, \’none\’ );
  8. ;

the_posts_pagination() / get_the_posts_pagination()

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

  1.  ( have_posts() ) :
  2.      ( have_posts() ) : the_post();
  3.         get_template_part( \’content\’, get_post_format() );
  4.     ;
  5.     the_posts_pagination();
  6.  :
  7.     get_template_part( \’content\’, \’none\’ );
  8. ;

参考:

Exploring the Functions Added in WordPress 4.1

WordPress 4.1 Improvements for Theme Developers

    © 版权声明
    THE END
    喜欢就支持一下吧
    点赞0分享
    评论 抢沙发

    请登录后发表评论

      暂无评论内容