WordPress获取文章形式函数:get_post_format

WordPress函数get_post_format用于获取文章格式,如日志、聊天、相册等,便于为不同格式文章定制模板。参数为文章ID,默认null。标准格式文章返回空值。示例展示如何根据格式加载对应模板文件。

WordPress基础教程
阅读时间: 16 分钟
最后更新时间:2025年11月13日

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

扩展阅读

get_post_format()函数位于:wp-includes/post-formats.php

相关函数:

  • set_post_format()
  • has_post_format()
  • get_post_format_link()
  • get_post_format_string()
  • the_post_format_audio()
  • get_the_post_format_media()
  • get_content_audio()
  • the_post_format_chat()
  • get_the_post_format_chat()
  • get_content_chat()
  • add_chat_detection_format()
  • the_post_format_gallery()
  • get_content_galleries()
  • get_post_gallery_images()
  • the_post_format_image()
  • get_the_post_format_image()
  • get_content_images()
  • the_post_format_quote()
  • get_the_post_format_quote()
  • get_content_quote()
  • the_post_format_url()
  • get_the_post_format_url()
  • get_content_url()
  • the_post_format_video()
  • get_content_video()
  • the_remaining_content()
  • get_the_remaining_content()
  • get_post_format_meta()
  • post_format_content_class()
  • get_post_format_content_class()
  • post_formats_compat()

这篇文章有用吗?

点击星号为它评分!

平均评分 0 / 5. 投票数: 0

到目前为止还没有投票!成为第一位评论此文章。

小兽wordpress

小兽wordpress

技术负责人
小兽wordpress凭借多年的wordpress企业主题制作经验,坚持以“为用户而生的wordpress主题”为宗旨,累计为10万多家客户提供品质wordpress建站服务,得到了客户的一致好评。我们一直用心对待每一个客户,我们坚信:“善待客户,将会成为终身客户”。小兽wordpress能坚持多年,是因为我们一直诚信。

相关文章

如何让线上业务更上一层楼

还没有WordPress网站

还没有WordPress网站

不管你从事什么行业,WordPress都会为你提供一个专业的主题模板。在WordPress市场上有成千上万的免费主题,适合很多中小企业。

查看所有模板
已经有WordPress网站

已经有WordPress网站

小兽WordPress诚邀你一起学习WordPress,愿与各方携手升级改善您的WordPress网站,一起交流网站加速,网站优化等问题。

马上交个朋友
微信联系
chat 扫码联系
模板建站
挑选模板
网站定制
免费诊断
咨询热线
咨询热线

189-0733-7671

返回顶部