5ucms论坛
标题:
get_post_format()函数 用于获取文章的形式
[打印本页]
作者:
admin
时间:
2021-6-3 16:50
标题:
get_post_format()函数 用于获取文章的形式
语法
get_post_format( int $post = null )
复制代码
参数
$post_id 整数型,默认值:null 文章的ID
返回值
aside 日志
chat 聊天
gallery 相册
link 链接
image 图像
quote 引语
status 状态
video 视频
audio 音频
实例
get_template_part('content', get_post_format());
复制代码
get_template_part():根据get_post_format()返回的信息来加载content开头命名的相应的模板;
get_post_format():获取当前post的形式。
讲解
比如我们现在有一个模板 content-image.php
那么可以通过get_template_part(‘content’, get_post_format())调用,即如果当前post形式是image,也就是对应上面的返回值,那么就会调用模板content-image.php;如果返回的post分类模板不存在,那么就会使用默认post模板。
欢迎光临 5ucms论坛 (http://bbs.5ucms.com/)
Powered by Discuz! X3.2