前言介紹
- 這款 WordPress 外掛「Posts 2 Posts Relationships」是 2021-07-06 上架。
- 目前有 50 個安裝啟用數。
- 上一次更新是 2021-07-19,距離現在已有 1385 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
- 外掛最低要求 WordPress 4.7 以上版本才可以安裝。
- 外掛要求網站主機運作至少需要 PHP 版本 5.5 以上。
- 有 1 人給過評分。
- 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。
外掛協作開發者
外掛標籤
many-to-many | posts 2 posts | posts to posts | custom post types | posts relationships |
內容簡介
此外掛可讓您在任何類型的文章中建立多對多的關聯:文章、頁面、自訂文章類型等等。
方便的使用者介面可輕鬆設定文章之間的關聯,新的連接 metabox 會顯示在相關文章的編輯頁面上,其中包含搜尋文字、文章類型和項目過濾的選項。
可使用標準的 WP_Query() 和 get_posts() 來取得相關的文章。
使用獨立的資料庫表格,當文章狀態更改時會更新其關聯,並在文章刪除時刪除關聯。
使用 WP_Query 取得相關文章
// 在主循環中,不需要當前文章 ID(p2p_rel_post_id),如果您沒有設置它,將使用當前文章:
$args = array(
'p2p_rel_key' => 'prod_to_bars', // 這是您的連接鍵名稱。必填欄位。
'p2p_rel_post_id' => 1, // 文章 ID。在主循環中不需要。
'p2p_rel_direction' => 'any', // 連接方向。默認為 'any'。選填欄位。以下為詳細說明(可以是 'any' | 'from_to' | 'to_from')
// 在這裡您當然可以添加您需要的 WP 標準參數:文章類型、狀態、日期、分頁等等。
);
//(此時,與任何其他 WP 循環一樣):
// 建立查詢
$the_query = new WP_Query( $args );
// 循環
if ( $the_query->have_posts() ) {
echo '
- ';
- ' . get_the_title() . ' ';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '
}
echo '
} else {
// 找不到文章
echo '
Nothing related
';}
// 回復原來的文章資料
wp_reset_postdata();
使用 get_posts() 取得相關文章
// 在主循環中,不需要當前文章 ID(p2p_rel_post_id),如果您沒有設置它,將使用當前文章:
$args = array(
'p2p_rel_key' => 'prod_to_bars', // 這是您的連接鍵名稱。必填欄位。
'p2p_rel_post_id' => 1, // 文章 ID。在主循環中不需要。
'p2p_rel_direction' => 'any', // 連接方向。默認為 'any'。選填欄位。以下為詳細說明(可以是 'any' | 'from_to' | 'to_from')
'post_type' => 'any', // 過濾的文章類型,可以是陣列。選填欄位。預設為 'post'。(可以是 'any' 讀取所有文章)
'suppress_filters' => false // 必填欄位
// 在這裡您當然可以添加您需要的 WP 標準參數:文章類型、狀態、日期、分頁等等。
);
//(此時,與任何其他 WP 循環一樣):
$rel_posts = get_posts( $args );
print_r( $rel_posts );
直接取得相關文章資料庫資料
// 在主循環中,不需要使用當前文章 ID(element_id),如果您沒有設置它,將使用當前文章:
$args = array(
'key' => 'prod_to_bars', // 這是您的連接鍵名稱。必填欄位。
'element_id' => 1, // 文章 ID。在主循環中不需要。
'element_type' => 'any', // 過濾的文章類型,可以是陣列。選填欄位。預設為 'post'。(可以是 'any' 讀取所有文章)
'status' => 'any', // 過濾的文章狀態,可以是陣列。選填欄位。預設為 'publish'。(可以是 'any' 讀取所有文章)
'direction' => 'any', // 連接方向。默認為 'any'。選填欄位。以下為詳細說明(可以是 'any' | 'from_to' | 'to_from')
);
global $P2P_Relationships;
$rel_posts = $P2P_Relationships->get_raw ( $args );
// 只有文章陣列
原文外掛簡介
This plugin allows you to create many-to-many relationships between posts of any type: post, page, custom post types, etc.
Configure post 2 post connections easily in a friendly interface.
The new connection metaboxes will appear on the related post edition pages. Search text, post type and term combo filter available as option for it.
Use the standard WP_Query() and get_posts() to get the related posts.
Solid-rock relationships: use his own database table, updated on post status change and removed on post deletion.
Getting related: the WP_Query way
// inside main loop, current post ID (p2p_rel_post_id) not needed, current post will be used if you don't set it:
$args = array(
'p2p_rel_key' => 'prod_to_bars', // This is your connection key name. Required.
'p2p_rel_post_id' => 1, // The post ID. Inside main loop dont needed.
'p2p_rel_direction' => 'any', // The connection direction. 'any' by default. Optional. Explained below. ( can be 'any' | 'from_to' | 'to_from' )
// Of course, here you can add the standard WP arguments you need: post type, status, dates, pagination, etc.
);
// (at this point, as any other WP looping):
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
echo '
- ';
- ' . get_the_title() . '
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '
';
}
echo '
';
} else {
// no posts found
echo '
Nothing related
';
}
// Restore original Post Data
wp_reset_postdata();
Getting related: the get_posts() way
// inside main loop, current post ID (p2p_rel_post_id) not needed, current post will be used if you don't set it:
$args = array(
'p2p_rel_key' => 'prod_to_bars', // This is your connection key name. Required.
'p2p_rel_post_id' => 1, // The post ID. Inside main loop dont needed
'p2p_rel_direction' => 'any', // The connection direction. 'any' by default. Optional. Explained below. ( can be 'any' | 'from_to' | 'to_from' )
'post_type' => 'any', // The filtered post types, can be an array. Optional. 'post' by default. (can be 'any' for all)
'suppress_filters' => false // Required
// Of course, here you can add the standard WP arguments you need: post type, status, dates, pagination, etc.
);
// (at this point, as any other WP looping):
$rel_posts = get_posts ( $args );
print_r( $rel_posts );
Getting related: getting it raw
// inside main loop, current post ID (element_id) not needed, current post will be used if you don't set it:
$args = array(
'key' => 'prod_to_bars', // This is your connection key name. Required.
'element_id' => 1, // The post ID. Inside main loop dont needed.
'element_type' => 'any', // The filtered post types, can be an array. Optional. 'post' by default. (can be 'any' for all)
'status' => 'any' // The filtered post status, can be an array. Optional. 'publish' by default. (can be 'any' for all)
'direction' => 'any', // The connection direction. 'any' by default. Optional. Explained below. ( can be 'any' | 'from_to' | 'to_from' )
);
global $P2P_Relationships;
$rel_posts = $P2P_Relationships->get_raw ( $args );
// Only an array of related post IDs, not the posts objects.
print_r ( $rel_posts );
The connection direction
By default, the connections are bidirectional (any). However, you can get related posts only in one direction: ‘from_to’ or ‘to_from’.
You can do the same logic at interface level for your users in the backoffice: you can setup your connection hidding the from metabox or the to metabox (UI mode setting).
各版本下載點
- 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
- 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Posts 2 Posts Relationships」來進行安裝。
(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。
延伸相關外掛(你可能也想知道)
Custom Post Type UI 》Custom Post Type UI 提供了易於使用的界面,以便為您的網站註冊和管理自定義文章類型和分類法。, Custom Post Type UI Extended, CPTUI 協助建立自定義內容...。
Meta Box 》Meta Box 是一個強大、專業又輕量級的工具組,供開發者在 WordPress 中為任何自訂文章型別建立自訂的 Meta Box 與自訂欄位。, 透過 Meta Box,您可以使用超過...。
Pods – Custom Content Types and Fields 》使用「Pods Framework」在一個地方管理你所有自訂內容需求。, , , 建立內容類型,包括自訂文章類型、自訂分類、以及我們專屬的「進階內容類型」(ACT),...。
Sydney Toolbox 》Sydney Toolbox 外掛只適用於 Sydney WordPress 主題。, 此外掛註冊了在 Sydney 主題 中所需的自定義文章類型和自定義欄位。。
Essential Content Types 》Essential Content Types 是一個 WordPress 外掛程式,讓您可以在您的網站上以不同的內容/文章類型展示出優秀的內容。這些內容/文章類型可能會被 WordPress ...。
Apollo13 Framework Extensions 》Apollo13 Framework Extensions 為建立在 Apollo13 Framework 上的主題增加了一些功能。這些功能包括:, , 設計匯入器, 基於 Apollo13 Framework 功能的短代...。
Custom Post Types and Custom Fields creator – WCK 》WordPress Creation Kit 是由三個工具組成,可幫助您建立和維護自訂文章類型、自訂分類和最重要的是文章、頁面或自訂文章類型的自訂欄位和元框。, WCK Custom...。
MAS Static Content 》MAS Static Content 是一款免費的 WordPress 外掛,可讓你建立自訂文章型態的靜態內容,並使用 shortcode 嵌入網頁。, 使用 [mas_static_content] shortcode ...。
Ultimate Posts Widget 》在您的免費虛擬網站上試用:點擊此處 => https://tastewp.com/plugins/ultimate-posts-widget., (此技巧適用於 WP 市集中的所有外掛 – 只需將 URL 中的“w...。
Posts 2 Posts 》此外掛允許您在任何類型的文章、頁面或自訂文章之間建立多對多的關係。以下是一些使用範例:, , 手動編輯有關聯的文章清單, 文章系列, 產品與零售商之間的關...。
Posts in Page 》使用簡單的簡碼 (shortcodes),輕鬆地將一個或多個文章添加到任何頁面。, 支援類別 (categories)、標籤 (tags)、自訂文章類型 (custom post types)、自訂稅項...。
Post Types Unlimited 》Post Types Unlimited 是一個輕鬆的方式,可以以正確的方式向你的 WordPress 網站添加自訂文章類型和自訂分類法 (taxonomy)。此外,這個外掛與任何佈景主題都...。
Meteor Slides 》Meteor Slides 讓您輕鬆製作幻燈片並使用 shortcode、小工具或模板標籤發佈它們。 幻燈片支援響應式和流體佈景主題,可適應任何設備並支援觸控。 使用超過20...。
MB Custom Post Types & Custom Taxonomies 》MB Custom Post Types & Custom Taxonomies 可以在 WordPress 中提供簡單易用的 UI 來輕鬆註冊和編輯自定義文章類型和分類法,並且可以處理所有文章類型...。
Custom Post Type Maker 》Custom Post Type Maker 是一款完美的外掛,以用戶友好的方式創建自定義文章類型和自定義分類法,就像管理常規文章和頁面一樣。, 原始作者為 Bakhuys。, 功能...。