post-formats 是 add_theme_support() 函式裡面的其中一個參數,宣告使用這個參數,可以幫文章分類,但這個分類,並不是一般文章的那種內容分類,而是可以用來依據不同種類載入不同的樣板,讓我們可做更豐富的排版。

當宣告使用時,在編輯文章的右側區域就會看到這個『格式』項目。

語法:

請在佈景的 functions.php 加入以下語法。

add_theme_support( ‘post-formats’, array( ‘video’, ‘audio’, ‘chat’ ) );

使用:
在樣板裡面,可以使用 get_template_part( ‘content’, get_post_format()) 的方式,引入相關子樣板使用,例如 get_post_format() 是 video 就會引入 content-video.php 使用。如果沒有這個子樣板,就會回去找 content.php ,所以使用方式相當彈性。
其他可用參數:

aside = 獨白
gallery = 藝廊
link = 連結
image = 圖片
quote = 引文
status = 狀態
video = 影片
audio = 音訊
chat = 閒聊