[WordPress] 外掛分享: Posts By Tag

前言介紹

  • 這款 WordPress 外掛「Posts By Tag」是 2009-07-26 上架。
  • 目前有 1000 個安裝啟用數。
  • 上一次更新是 2021-10-13,距離現在已有 1309 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
  • 外掛最低要求 WordPress 4.0 以上版本才可以安裝。
  • 有 15 人給過評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

sudar |

外掛標籤

tag | cache | posts | widget | sidebar |

內容簡介

Posts By Tag 是一款 WordPress 外掛,提供側邊欄小工具,可以用來在側邊欄中顯示特定標籤的文章。

可以在小工具中指定這些標籤,或讓外掛自動從當前文章的標籤、文章 slug 或自訂欄位中檢索它們。自訂欄位可以在文章或頁面編輯屏幕中指定。

您也可以使用短碼或模板函數來顯示文章。

外掛分別緩存每個小工具的文章,並且僅在需要時發出數據庫查詢。這將減少每頁加載時涉及的數據庫查詢量,因此對您的服務器負擔輕。如果這與其他外掛衝突,您也可以選擇禁用它。

特色
側邊欄小工具

Posts By Tag 外掛提供了一個側邊欄小工具,可以配置它來顯示來自側邊欄中一組標籤的文章。您可以擁有多個小工具,為每個小工具配置不同的標籤集。

每個小工具都允許您選擇

從哪些標籤中選擇文章(或排除文章)
要顯示的文章數
是否從當前文章中獲取標籤
是否從當前文章的 slug 中取標籤
是否從當前文章的自訂欄位中取標籤
啟用文章概要與文章標題一起顯示的選項。
如果有,啟用文章縮略圖顯示的選項。
顯示文章作者的選項。
顯示文章日期的選項。
顯示文章內容的選項。
選擇文章顯示的順序。
排除當前文章/頁面的選項。
為鏈接指定目標屬性的選項
顯示到標籤存檔頁的鏈接的選項。
如有需要,禁用快取的選項。
啟用 Google Analytics 追蹤鏈接的選項

要添加小工具,在 WordPress 管理控制台中登錄並進入外觀 -> 小工具。您會找到名為“Posts By Tag”的小工具。將其拖放到您希望小工具顯示的側邊欄中。

模板函數

除了使用小工具外,您也可以使用以下模板函數,在主題中的任何位置顯示來自一組標籤的文章。

posts_by_tag($tags, $options);

可以在 $options 陣列中傳遞以下選項

$tags (string) – 一組逗號分隔的標籤。如果留空,則使用當前文章的標籤。
$options (array) – 一組選項。允許以下字段

number (number) – 預設 5 – 要顯示的文章數
tag_from_post (bool) – 預設為 FALSE – 是否要從當前文章的標籤中檢索標籤
tag_from_post_slug (bool) – 預設為 FALSE – 是否要從當前文章的 slug 中檢索標籤
tag_from_post_custom_field (bool) – 預設為 FALSE – 是否要從當前文章的自訂欄位中檢索標籤
exclude (bool) – 預設為 FALSE – 是否包含標籤或排除標籤
excerpt (bool) – 預設 FALSE – 是否顯示文章概要
excerpt_filter (bool) – 預設為 TRUE 是否啟用文章摘要過濾器
thumbnail (bool) – 預設為 FALSE – 是否顯示文章縮略圖
thumbnail_size (string/array) – 預設為

原文外掛簡介

Posts By Tag WordPress Plugin, provides sidebar widgets which can be used to display posts from a specific set of tags in the sidebar.
These tags can be specified in the widget or the Plugin can automatically retrieve them from the current post tags, post slug or form custom field. The custom fields can be specified in the edit post or page screen.
You can also use shortcode or template function to display the posts.
The Plugin caches the posts of each widget separately, and issues database queries only when needed. This will reduce the amount of database queries involved for each page load and will therefore be light on your server. If this clashes with other Plugins, you also have an option to disable it.
Features
Sidebar Widget
Posts By Tag Plugin provides a sidebar widget which can be configured to display posts from a set of tags in the sidebar. You can have multiple widgets with different set of tags configured for each one of them.
Each widget allows you to choose

The set of tags from where posts should be selected (or excluded)
The number of posts to be displayed.
Whether to pick the tags from current post
Whether to pick the tags from current post slug
Whether to pick the tags from current post’s custom field
Option to enable post excerpts to be displayed with post titles.
Option to display post thumbnail if present.
Option to display post author.
Option to display post date.
Option to display post content.
Choose the order in which the posts should be displayed.
Option to exclude current post/page.
Option to specify the target attribute for links
Option to display links to tag archive pages.
Option to disable the cache if needed.
Option to enable Google Analytics tracking on the links

To add the widget, log into your WordPress admin console and go to Appearances -> Widgets. You will find the widget with the title “Posts By Tag”. Drag and drop it in the sidebar where you want the widget to be displayed.
Template function
In addition to using the widget, you can also use the following template function to display posts from a set of tags, anywhere in the theme.
posts_by_tag($tags, $options);

The following options can be passed in the $options array

$tags (string) – set of comma separated tags. If you leave this empty, then the tags from the current post will be used.
$options (array) – set of options. The following are the fields that are allowed

number (number) – default 5 – number of posts to display
tag_from_post (bool) – default FALSE – whether to pick up tags from current post’s tag
tag_from_post_slug (bool) – default FALSE – whether to pick up tags from current post’s slug
tag_from_post_custom_field (bool) – default FALSE – whether to pick up tags from current post’s custom field
exclude (bool) – default FALSE – Where to include the tags or exclude the tags
excerpt (bool) – default FALSE – To display post excerpts or not
excerpt_filter (bool) – default TRUE Whether to enable or disable excerpt filter
thumbnail (bool) – default FALSE – To display post thumbnails or not
thumbnail_size (string/array) – default thumbnail – Size of the thumbnail image. Refer to https://codex.wordpress.org/Function_Reference/get_the_post_thumbnail#Thumbnail_Sizes
order_by (date,title, random) – default date – Whether to order by date or by title or show them randomly
order (asc,desc) – default desc – To change the order in which the posts are displayed.
author (bool) – default FALSE – To display author name or not.
date (bool) – default FALSE – To display post date or not.
content (bool) – default FALSE – To display post content or not.
content_filter (bool) – default TRUE Whether to enable or disable content filter
exclude_current_post (bool) – default TRUE – To exclude current post/page.
tag_links (bool) – default FALSE – To display link to tag archive page or not.
link_target (string) – default empty – target attribute for the permalink links.

In addition to the above options the following options are available in the Pro addon

campaign (string) – The Google Analytics campaign code that needs to be appended to every link
event (string) – The Google Analytics events code that needs to be appended to every link

You can checkout some example PHP code that shows how you can call the template function with different options.
Shortcode
You can also include the following shortcode in your blog posts or WordPress page, to display the posts from the set of tags.
posts-by-tag tags = "tag1, tag2"]

All the parameters that are accepted by the template tag can also be used in the shortcode.
You can checkout some example shortcodes that shows how you can use the shortcode with different options.
Custom field
You can also specify the tags for each post or page and a custom title using custom field. The UI for the custom field is available on the right side of the add/edit post/page screen in WordPress admin console.
Styling using CSS
The Plugin adds the following CSS classes. If you want to customize the look of the widget then can change it by adding custom styles to these CSS classes and ids.

The UL tag has the class posts-by-tag-list
Every LI tag has the class posts-by-tag-item
Every LI tag also has all tags names to which the post belongs as part of the class attribute
Each LI tag also has the id posts-by-tag-item-{id}, where id is the post id.
Each tag inside LI that contains title has the class posts-by-tag-item-title.

If you want to output categories of the post as class names(so that you can style them differently), then you can get the code from this forum thread.
Caching
If you are using the widget, then the Plugin automatically caches the db queries. This will greatly improve the performance of you page. If this clashes with other Plugins or if you want to manage the cache yourself, then you disable the cache if needed.
However if you are going to use the shortcode or the template directly, then you might have to cache the output yourself.
Development and Support
The development of the Plugin happens over at github. If you want to contribute to the Plugin, fork the project at github and send me a pull request.
If you are not familiar with either git or Github then refer to this guide to see how fork and send pull request.
If you are looking for ideas, then you can start with one of the following TODO items 🙂
TODO
The following are the features that I am thinking of adding to the Plugin, when I get some free time. If you have any feature request or want to increase the priority of a particular feature, then let me know by adding them to github issues.

Provide template tags for widget title, that will be dynamically expanded.
Add support for custom post types
Ability to sort posts alphabetically
Ability to exclude posts by id
Ability to show comment count
Ability to retrieve posts by date range
Ability to pull posts randomly. – Added in v3.0

Support

If you have found a bug/issue or have a feature request, then post them in github issues
If you have a question about usage or need help to troubleshoot, then post in WordPress forums or leave a comment in Plugins’s home page
If you like the Plugin, then kindly leave a review/feedback at WordPress repo page.
If you find this Plugin useful or and wanted to say thank you, then there are ways to make me happy 🙂 and I would really appreciate if you can do one of those.
Checkout other WordPress Plugins that I have written
If anything else, then contact me in twitter.

Translation

Swedish (Thanks Gunnar Lindberg Årneby)
Turkish (Thanks Yakup Gövler)
Belorussian (Thanks FatCow)
German (Thanks Renate)
Dutch (Thanks Rene)
Hebrew (Thanks Sagive SEO)
Spanish (Thanks Brian Flores of InMotion Hosting)
Bulgarian (Thanks Nikolay Nikolov of [IQ Test)
Lithuanian (Thanks Vincent G)
Hindi (Thanks Love Chandel)
Gujarati (Thanks Punnet of Resolutions Mart)

The pot file is available with the Plugin. If you are willing to do translation for the Plugin, use the pot file to create the .po files for your language and let me know. I will add it to the Plugin after giving credit to you.
Readme Generator
This Readme file was generated using wp-readme, which generates readme files for WordPress Plugins.

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Posts By Tag」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


0.1 | 0.2 | 0.3 | 0.4 | 0.5 | 0.6 | 0.7 | 0.8 | 1.0 | 1.1 | 1.2 | 1.3 | 1.4 | 1.5 | 1.6 | 1.7 | 1.8 | 1.9 | 2.0 | 2.1 | 2.2 | 2.3 | 2.4 | 2.5 | 2.6 | 2.7 | 2.8 | 2.9 | 3.0 | 3.1 | 3.2 | 2.1.1 | 2.7.1 | 2.7.2 | 2.7.3 | 2.7.4 | 3.0.1 | 3.0.2 | 3.0.3 | 3.0.4 | 3.1.1 | 3.1.2 | 3.1.3 | 3.2.1 | trunk |

延伸相關外掛(你可能也想知道)

文章
Filter
Apply Filters
Mastodon