1. 主页
  2. 文档
  3. WordPress函数
  4. get_post_format

get_post_format

WordPress函数get_post_format用于获取文章的形式,在为不同形式的文章制作不同的模板时非常有用。

get_post_format( int $post = null )

参数

$post_id

整数型,默认值:null

文章的ID

函数返回值

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

注意: 标准形式的文章不会返回任何值。

get_post_format()函数使用示例

$format = get_post_format();
get_template_part( 'format', $format );

举例2:

// Include the Post-Format-specific template for the content.
get_template_part( 'template-parts/content', get_post_format() );
这篇文章对您有用吗?

我们要如何帮助您?