
內容簡介
這個外掛提供一個短碼(shortcode)以ID編號取得文章內容。
預設情況下,內容會經過wpautop()和do_shortcode()處理,除非你使用下方顯示的屬性或過濾器來控制。
範例
[post-content id="42"]
這個範例會取得編號為42的文章內容。
[post-content id="42" autop="false"]
這個範例會取得編號為42的文章內容,但不會進行 wpautop 處理。
[post-content id="42" shortcode="false"]
這個範例會取得編號為42的文章內容,但不會進行 do_shortcode 處理。
[post-content id="42" autop="false" shortcode="false"]
這個範例會取得編號為42的文章內容,但不會進行 wpautop 或 do_shortcode 處理。
[post-content id="42" status="publish,future"]
這個範例只會取得編號為42的文章,且狀態必須是「publish」或「future」。
[post-content id="42" field="excerpt"]
這個範例會取得編號為42的文章摘錄(excerpt)。
注意:
所包含的文章內容可能仍會進行 wpautop 處理。
屬性
id – 整數
文章 ID
autop – 布林值 – 預設: true
以下任何值都等於 true:true、1、yes。其他所有值都等於false。
shortcode – 布林值 – 預設: true
以下任何值都等於 true:true、1、yes。其他所有值都等於false。
status – 文字 – 預設: publish
任何預設或自訂的 WordPress 狀態值(publish、draft、future 等等)。
如果 WordPress 沒有註冊狀態,則會使用預設值。
field – 文字 – 預設: post_content
您想要擷取的資料庫欄位名稱。
如果欄位名稱不在允許的欄位名稱陣列中,則會使用此預設值。
過濾器
您可以使用此過濾器修改允許擷取的欄位。
add_filter('post-content-allowed-fields', function($allowed_fields) {
// 在這裡進行您的篩選。
return $allowed_fields;
});
您可以指定預設的 shortcode 屬性值。
add_filter('post-content-default-attributes', function ($default_attributes) {
// 在這裡輸入您的程式碼。
return $default_attributes;
});
您可以按短碼用途篩選屬性。
add_filter('shortcode_atts_post-content', function ($out, $pairs, $attributes) {
// 在這裡輸入您的程式碼。
return $out;
}, 10, 3);
外掛標籤
開發者團隊
原文外掛簡介
This plugin provides a shortcode to get the content of a post based on ID number.
By default, the content will be passed through wpautop() and do_shortcode() unless you tell it not to by using attributes or filters as shown below.
Examples
[post-content id="42"]
This gets the content of post 42.
[post-content id="42" autop="false"]
This gets the content of post 42 and does not call wpautop on the content.
[post-content id="42" shortcode="false"]
This gets the content of post 42 and does not call do_shortcode on the content.
[post-content id="42" autop="false" shortcode="false"]
This gets the content of post 42 and does not call wpautop or do_shortcode on the content.
[post-content id="42" status="publish,future"]
This gets the content of post 42 only if the post_status is “publish” or “future”.
[post-content id="42" field="excerpt"]
This gets the excerpt of post 42.
Note:
The containing post may still have wpautop called on it’s content.
Attributes
id – integer
The post ID
autop – boolean – default: true
The following values equal true: true, 1, yes. All other values equal false.
shortcode – boolean – default: true
The following values equal true: true, 1, yes. All other values equal false.
status – text – default: publish
Any default or custom WordPress status value (publish, draft, future, etc.).
The default value will be used if the status is not registered with WordPress.
field – text – default: post_content
The name of the database column you want to retrieve.
This default value will be used if the column name is not in the array of allowed field names.
Filters
You can modify the fields that are allowed to be retrieved with this filter.
add_filter('post-content-allowed-fields', function($allowed_fields) {
// Do your filtering here.
return $allowed_fields;
});
You can specify the default shortcode attribute values.
add_filter('post-content-default-attributes', function ($default_attributes) {
// Your code here.
return $default_attributes;
});
You can filter attributes per shortcode usage
add_filter('shortcode_atts_post-content', function ($out, $pairs, $attributes) {
// Your code here.
return $out;
}, 10, 3);
