国内外主机
测评及优惠码

WordPress4.1新的函数介绍

wordpress 4.1也更新了一阵子了,作为一般用户最关系的就是新的wordpress主题,作为开发者,新增函数也给我们带来了更多的便捷和惊喜,今天就转载一篇介绍wordpress4.1中新增的主题函数,做个备忘

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() / get_the_archive_title()

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

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

 

the_archive_description() / get_the_archive_description()

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

he_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;

 

赞一个
赞(0)
版权声明:本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权
文章名称:《WordPress4.1新的函数介绍》
文章链接:https://www.ibytx.com/1234.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

登录

找回密码

注册