WordPress 4.1 新增函数

WordPress113.7K阅读模式

最近正忙于新主题的制作,转篇关于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. function 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 class="page-title">', '</h1>' );

the_archive_description() / get_the_archive_description()

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

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

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

the_post_navigation() / get_the_post_navigation()

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

  1. while ( have_posts() ) : the_post();
  2.     get_template_part( 'content', get_post_format() );
  3.     the_post_navigation();
  4. endwhile// end of the loop.

the_posts_navigation() / get_the_posts_navigation()

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

  1. if ( have_posts() ) :
  2.     while ( have_posts() ) : the_post();
  3.         get_template_part( 'content', get_post_format() );
  4.     endwhile;
  5.     the_posts_navigation();
  6. else :
  7.     get_template_part( 'content', 'none' );
  8. endif;

the_posts_pagination() / get_the_posts_pagination()

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

  1. if ( have_posts() ) :
  2.     while ( have_posts() ) : the_post();
  3.         get_template_part( 'content', get_post_format() );
  4.     endwhile;
  5.     the_posts_pagination();
  6. else :
  7.     get_template_part( 'content', 'none' );
  8. endif;

参考:

Exploring the Functions Added in WordPress 4.1

WordPress 4.1 Improvements for Theme Developers

本站文章大部分始于原创,用于个人学习记录,可能对您有所帮助,仅供参考!

weinxin
我的微信
版权声明
本站原创文章转载请注明文章出处及链接,谢谢合作!
 
知更鸟
评论  11  访客  9
    • 寻金笔记
      寻金笔记 6

      好期待 :mrgreen:

      • Louis Han
        Louis Han 6

        又有插件要丢掉了

        • Kael Li
          Kael Li 1

          新主题?CMS的?鸟哥,我好期待啊……

          • 床板上滴鱼
            床板上滴鱼 2

            鸟哥威武,期待放图,先瞧瞧 :wink:

            • 冰镇椰子汁
              冰镇椰子汁 2

              支持鸟哥,支持鸟哥的新主题

              • 绿色节能减排
                绿色节能减排 1

                鸟哥 弄个知更鸟 WP官方群吧,方便我们这些鸟粉交流经验! :grin:

                • 扭纹柴
                  扭纹柴 1

                  支持鸟哥~ :wink:

                  • 艾博
                    艾博 2

                    期待新主题!

                    • 寻金笔记
                      寻金笔记 6

                      新主题大赞!!!好喜欢 :wink: :wink: :wink:

                    评论已关闭!