
內容簡介
這個外掛提供一個強大的小工具、簡碼(包括簡碼建構工具)和模板標籤,方便檢索和顯示文章或頁面的自訂欄位值。
自訂欄位的威力讓這個外掛具有成為數十個外掛的潛力。
這個外掛讓您利用自訂欄位/元數據的威力。使用「取得自訂欄位」小工具、[custom_field] 簡碼(具有文章編輯器側邊欄小工具,協助您建立簡碼)或其中六個模板標籤之一,取得和顯示自訂欄位。找尋現有文章的自訂欄位、指定文章的自訂欄位、最近的文章的自訂欄位,或隨機選取自訂欄位中的值。對於外掛發現的自訂欄位值,您可以選擇性地指定要在結果之前和之後顯示的文字或 HTML。如果找不到任何結果,則不顯示任何內容(除非您定義搜索不到時顯示的文字)。如果有多個結果,只顯示第一個,除非您指定用於連接所有結果的字串(例如「,」)。請訪問「範例」部分了解如何多種方式使用這個外掛程式。
此外掛提供六個模板標籤。這裡是它們,以及它們使用的解釋:
- c2c_get_custom():在「迴圈」內使用這個為文章檢索自訂欄位值的模板標籤。
- c2c_get_current_custom():僅在永久網址文章模板(single.php)和頁面模板(page.php)上可用。可以在「迴圈」內或「迴圈」之外使用。可用於使用自訂欄位來定義您想要包含在文章或頁面標題、頁角或側邊欄中的文字。
- c2c_get_post_custom():當您知道您要取得自訂欄位值的文章 ID 時,這很有用。
- c2c_get_random_custom():隨機查找指定自訂欄位鍵的實例中的值,只要該欄位與已發佈的文章、非密碼保護的文章相關聯即可(您可以在外掛檔案中修改設定以搜索加密文章)。
- c2c_get_random_post_custom():當您知道您有興趣的文章的 ID 時,從文章中檢索隨機的自訂欄位值。
- c2c_get_recent_custom():從指定的自訂欄位中檢索最近(根據關聯文章的發布日期)的值。
您可以過濾外掛會顯示的自訂欄位值。為「the_meta」添加過濾器以過濾自訂欄位數據(請參閱代碼文件末尾的已註釋樣本)。您也可以通過鉤取「the_meta_$sanitized_field」添加每個自訂欄位的過濾器。$sanitized_field 是 $field 值的乾淨版本,其中除了字母和底線字符之外的所有內容都被刪除。因此,要篩選「相關文章」自訂欄位的值,您需要為「the_meta_RelatedPosts」添加過濾器。
鏈接:外掛首頁 | 外掛目錄 | GitHub | 作者首頁
開發者文檔
開發者文檔位於 DEVELOPER-DOCS.md。該文件涵蓋了數條模板標籤、鉤子和簡分的說明。
外掛標籤
開發者團隊
原文外掛簡介
This plugin provides a powerful widget, shortcode (with shortcode builder tool), and template tags for easily retrieving and displaying custom field values for posts or pages.
The power of custom fields gives this plugin the potential to be dozens of plugins all rolled into one.
This plugin allows you to harness the power of custom fields/meta data. Use the “Get Custom Field” widget, the [custom_field] shortcode (which has a post editor sidebar widget to help you build the shortcode), or one of six template tags to retrieve and display custom fields. Find a custom field for the current post, a specified post, a recent post, or randomly. And for the custom field values found by the plugin, you may optionally specify text or HTML to appear before and after the results. If nothing is found, then nothing is display (unless you define text to appear when no results are found). If multiple results are found, only the first will be displayed unless you specify a string to be used to join the results together (such as “,”), in which case all will be returned. Visit the Examples section to see how this plugin can be cast in dozens of different ways.
There are six template tags provided by this plugin. Here they are, with an explanation of when they are appropriate for use:
c2c_get_custom() : Use this inside “the loop” to retrieve a custom field value for a post
c2c_get_current_custom() : This is only available on the permalink post template (single.php) and page template (page.php). Can be used inside or outside “the loop”. Useful for using custom field to define text you want to include on a post or page’s header, footer, or sidebar.
c2c_get_post_custom() : Useful when you know the ID of the post whose custom field value you want.
c2c_get_random_custom() : Retrieve the value of a random instance of the specified custom field key, as long as the field is associated with a published posted, non-passworded post (you can modify a setting in the plugin file to search passworded posts as well).
c2c_get_random_post_custom() : Retrieves the value of random custom field(s) from a post when you know the ID of the post you’re interested in.
c2c_get_recent_custom() : Retrieves the most recent (according to the associated post’s publish date) value of the specified custom field.
You can filter the custom field values that the plugin would display. Add filters for ‘the_meta‘ to filter custom field data (see the end of the code file for commented out samples you may wish to include). You can also add per-meta filters by hooking ‘the_meta_$sanitized_field‘. $sanitized_field is a clean version of the value of $field where everything but alphanumeric and underscore characters have been removed. So to filter the value of the “Related Posts” custom field, you would need to add a filter for ‘the_meta_RelatedPosts‘.
Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage
Developer Documentation
Developer documentation can be found in DEVELOPER-DOCS.md. That documentation covers the numerous template tags, hooks, and shortcode provided by the plugin.
As an overview, these are the template tags provided the plugin:
c2c_get_custom() : Template tag for use inside “the loop” and applies to the currently listed post.
c2c_get_current_custom() : Template tag for use on permalink (aka single) page templates for posts and pages.
c2c_get_post_custom() : Template tag for use when you know the ID of the post you’re interested in.
c2c_get_random_custom() : Template tag for use to retrieve a random custom field value.
c2c_get_random_post_custom() : Template tag for use to retrieve random custom field value(s) from a post when you know the ID of the post you’re interested in.
c2c_get_recent_custom() : Template tag for use outside “the loop” and applies for custom fields regardless of post.
These are the hooks provided by the plugin:
c2c_get_custom_field_values_shortcode : Filter to customize the name of the plugin’s shortcode.
c2c_get_custom_field_values_post_types : Filter to customize the post types that should support the shortcode builder metabox.
get_custom_field_values/can_author_use_shortcodes : Filter to customize if post author can make use of the ‘custom_field’ shortcode.
get_custom_field_values/show_metabox : Filter to customize if the shortcode builder metabox is shown.
The shortcode provided is [custom-field], which has a number of attributes to customize its behavior and output.
