5ucms论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 9216|回复: 0

[钩子/函数] get_post_format()函数 用于获取文章的形式

[复制链接]

670

主题

785

帖子

8228

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
8228
发表于 2021-6-3 16:50:46 | 显示全部楼层 |阅读模式
语法

  1. get_post_format( int $post = null )
复制代码


参数

$post_id 整数型,默认值:null 文章的ID

返回值

aside 日志
chat 聊天
gallery 相册
link 链接
image 图像
quote 引语
status 状态
video 视频
audio 音频
实例

  1. 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模板。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|5ucms.com

GMT+8, 2024-3-29 19:52 , Processed in 0.078125 second(s), 30 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表