get_template_part、get_post_format函数使用

来源:互联网 发布:html网页引用js文件 编辑:程序博客网 时间:2024/06/03 13:14

get_template_part('slug',get_post_format());

get_template_part():根据get_post_format()返回的信息来加载slug开头命名的相应的模板;

get_post_format():获取当前post的分类信息。

例子:

现有模板 content-image.php

那么get_template_part('content',get_post_format());如果当前post分类是image,那么就会调用模板content-image.php;如果返回的post分类模板不存在,那么就会使用默认post模板。