
內容簡介
你的網站有使用分類和標籤嗎?你有使用自訂分類嗎?如果是,這個外掛程式會根據你所有的分類找到類似的內容。
顯示相關的文章有兩種方式:
第一種是使用提供的小工具在文章中顯示相關內容,這只適用於‘is_single()’為true的情況。
第二種是使用‘pk_related_return($post->ID);’函數,在需要的地方進行程式設計呼叫。
這個外掛程式提供的小工具可以讓你選擇要顯示的文章數量,還有欄位選項有:特色圖片、作者、日期和摘要(標題是必需的)。你可以決定要顯示哪種特色圖片:縮略圖、中等大小、大型或完整尺寸,版本2.0以上,你現在可以決定‘類似文章’排序是新的文章還是與現在這篇文章創建日期更接近的文章。
如果你發現小工具不能滿足你的需求,或者選擇太少,你可以使用以下函數來進行程式設計:
pk_related_return($post->ID, $args);
其中,$post->ID是要顯示相關文章的文章ID。
$args參數是一個陣列,你可以使用以下的值(更多的值很快就會推出):
posts_per_page(int預設值為5)
thumbnail_size(字符串,包含這些值之一:“thumbnail”, “medium”, “large”, “full”。預設為縮略圖)
sort_prefer(字符串,包含這些值之一:“newest”, “closest”。預設為最新)
例如:
<?php
$args = array (
'posts_per_page' => 6,
'thumbnail_size' => 'medium',
'sort_prefer' => 'closest'
);
pk_related_return的返回值是一個對象陣列,其中包括WordPress文章表中的大部分欄位,還有永久鏈接和特色圖片。
未來的功能:
允許使用者在請求中只指定某些內容類型(文章、頁面、自訂),這樣你就可以只返回產品或者只返回文章。這只有在不同內容類型之間分享分類時才會有問題。
外掛標籤
開發者團隊
原文外掛簡介
Does your website utilize categories and tags? Does it use custom taxonomies? If so, this plugin will find similar content
based on all your taxonomies. There are two ways to show related posts within your page.
The first way to show related content on your post is to use the widget provided. This only works when is_single() is true
The second way to show similar content on your site is to use the pk_related_return($post->ID); function which can be
called programmatically anywhere you wish!
The Widget included with this plugin gives you the option to limit the amount of posts; it allows you to determine which
fields to show: Featured Image, Author, Date, and Excerpt (Title is required); it allows you to determine which
variant of the featured image to show: thumbnail, medium, large, or full. As of version 2.0, you can now decide whether the
‘similar posts’ sorting prefers posts that are newer or posts that were created closer to the date of the post you’re
viewing.
If you find the Widget doesn’t meet your needs or is too limiting, you can call the functionality programmatically using
this function:
pk_related_return($post->ID, $args);
Where $post->ID is the ID of the post for which you are wanting to show related articles.
The $args parameter is an array with the following values available to you (more coming soon):
posts_per_page (int defaults to 5)
thumbnail_size (string consisting of one of these values: “thumbnail”, “medium”, “large”, “full”. Defaults to thumbnail).
sort_prefer (string consisting of one of these values: “newest”, “closest”. Defaults to newest).
An example might be:
6,
'thumbnail_size' => 'medium',
'sort_prefer' => 'closest'
);
The return value of pk_related_return is an array of objects that includes most of the fields within WordPress’s posts
table plus permalink and featured image.
Future Additions:
Allow the user to specify only certain content types (posts, pages, custom) in a request. This would allow you to specify
only products get returned, or only blog posts. This would only be an issue if content types share taxonomies.
