[WordPress] 外掛分享: Tweets Widget

前言介紹

  • 這款 WordPress 外掛「Tweets Widget」是 2016-08-26 上架。
  • 目前有 30 個安裝啟用數。
  • 上一次更新是 2016-08-29,距離現在已有 3170 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
  • 外掛最低要求 WordPress 3.5.1 以上版本才可以安裝。
  • 有 1 人給過評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

fossasia |

外掛標籤

oauth | loklak | tweets | twitter | loklak api |

內容簡介

此外採用匿名的 Loklak API,或是連結您的 Twitter 帳號至這個外掛,這個小工具會顯示您在 Twitter 上最新的張貼。

這個外掛相容於新的 Twitter API 1.1,可透過 WordPress 的管理後台進行 OAuth 認證。

短碼

您可以透過 WordPress 的短碼「[tweets]」在文章內建立嵌入式的推文。

要嵌入別的使用者的時間線,請新增「user」屬性。
要重載預設的 5 條推文,請新增「max」屬性,例如:

[tweets max=10 user=KhoslaSopan]

Theming

對於初學者,您可以透過 WordPress 內建功能調整 HTML。
請參考小工具氾濫
以及小工具的佈景主題

CSS

這個外掛本身不含有 CSS,目的是要讓您可以視情況自行設計風格。

這個外掛會將推文以列表樣式呈現,您可以利用各種鈎子進行設計。以下是一個簡單範本:

.tweets {
/* 設計推文列表 */
}
.tweets h3 {
/* 設計標頭 */
}
.tweets ul {
/* 設計列表 */
}
.tweets li {
/* 設計項目 */
}
.tweets .tweet-text {
/* 設計主要的推文 */
}
.tweets .tweet-text a {
/* 設計連結、主題標籤及提及 */
}
.tweets .tweet-text .emoji {
/* 設計內嵌在推文中的表情符號圖片 */
}
.tweets .tweet-details {
/* 設計推文日期時間及連結 */
}

自訂 HTML

如果您想要覆蓋推文的預設標記,以下的鈎子也提供了額外功能:

在小工具標題和推文之間新增標題,可使用 tweets_render_before
透過 tweets_render_date 個人化繪製日期時間戳記
透過 tweets_render_text 個人化繪出單一推文的 HTML
透過 tweets_render_tweet 以個人化方式繪製每個複合推文
覆蓋推文的無序列表,可使用 tweets_render_list
在小工具結束前新增页脚,可使用 tweets_render_after

以下是在佈景主題的 functions.php 檔案中使用以上功能的範例:

add_filter('tweets_render_date', function( $created_at ){
$date = DateTime::createFromFormat('D M d H:i:s O Y', $created_at );
return $date->format('d M h:ia');
}, 10 , 1 );

add_filter('tweets_render_text', function( $text ){
return $text; // <- 使用預設值
}, 10 , 1 );

add_filter('tweets_render_tweet', function( $html, $date, $link, array $tweet ){
$pic = $tweet['user']['profile_image_url_https'];
return '

'.$html.'

'.$date.'

';
}, 10, 4 );

add_filter('tweets_render_after', function(){
return '

';
}, 10, 0 );

暫存

Twitter API 的回應預設會暫存 5 分鐘。這代表您的新推文不會在實時顯示於您的網站上。

這是為了效能而刻意而為之,同時也是為了避免 Twitter 程式嚴格執行的 15 分鐘內限制發出 15 個請求的規定。

您可以使用其他外掛或獨立的快取基礎設施,以提升效能並減少如此頻繁的 API 求取。

原文外掛簡介

Use anonymous Loklak API OR Connect your Twitter account to this plugin and the widget will display your latest tweets on your site.
This plugin is compatible with the new Twitter API 1.1 and provides full OAuth authentication via the WordPress admin area.
Shortcodes
You can embed tweets in the body of your posts using a WordPress the shortcode [tweets].
To specify a different user’s timeline add the user attribute.
To override the default number of 5 tweets add the max attribute, e.g:
[tweets max=10 user=KhoslaSopan]

Theming

For starters you can alter some of the HTML using built-in WordPress features.
See Widget Filters
and Widgetizing Themes
CSS
This plugin contains no default CSS. That’s deliberate, so you can style it how you want.
Tweets are rendered as a list which has various hooks you can use. Here’s a rough template:
.tweets {
/* style tweet list wrapper */
}
.tweets h3 {
/* style whatever you did with the header */
}
.tweets ul {
/* style tweet list*/
}
.tweets li {
/* style tweet item */
}
.tweets .tweet-text {
/* style main tweet text */
}
.tweets .tweet-text a {
/* style links, hashtags and mentions */
}
.tweets .tweet-text .emoji {
/* style embedded emoji image in tweet */
}
.tweets .tweet-details {
/* style datetime and link under tweet */
}

Custom HTML
If you want to override the default markup of the tweets, the following filters are also available:

Add a header between the widget title and the tweets with tweets_render_before
Perform your own rendering of the timestamp with tweets_render_date
Render plain tweet text to your own HTML with tweets_render_text
Render each composite tweet with tweets_render_tweet
Override the unordered list for tweets with tweets_render_list
Add a footer before the end of the widget with tweets_render_after

Here’s an example of using some of the above in your theme’s functions.php file:
add_filter('tweets_render_date', function( $created_at ){
$date = DateTime::createFromFormat('D M d H:i:s O Y', $created_at );
return $date->format('d M h:ia');
}, 10 , 1 );

add_filter('tweets_render_text', function( $text ){
return $text; // '.$html.'

'.$date.'

';
}, 10, 4 );

add_filter('tweets_render_after', function(){
return '

';
}, 10, 0 );

Caching

Responses from the Twitter API are cached for 5 minutes by default. This means your new Tweets will not appear on your site in real time.
This is deliberate not only for performance, but also to avoid Twitter’s strict rate limits of 15 requests every 15 minutes.
You can override the 300 second cache by using the tweets_cache_seconds filter in your theme as follows:
This would extend the cache to 1 minute, which is the lowest value you should consider using on a live site:
add_filter('tweets_cache_seconds', function( $ttl ){
return 60;
}, 10, 1 );

This would disable the cache (not recommended other than for debugging):
add_filter('tweets_cache_seconds', function( $ttl ){
return 0;
}, 10, 1 );

Emoji

If you want to disable Emoji image replacement, you can filter the replacement callback function to something empty, e.g:
add_filter('tweets_emoji_callback', function( $func ){
return '';
} );

or to strip Emoji characters from all tweets, return your own replacement function that returns something else, e.g:
add_filter(‘tweets_emoji_callback’, function( $func ){
return function( array $match ){
return ‘‘;
};
} );
Credits
Screenshot taken with permission from http://stayingalivefoundation.org/blog

Portuguese translations by Leandro Dimitrio

German translations by Florian Felsing and David Noh
Russian translations by Andrey Yakovenko
Dutch translations by Daniel Wichers
Spanish translations by Pedro Pica

Notes
Be aware of Twitter’s display requirements when rendering tweets on your website.
Example code here uses PHP closures which require PHP>=5.3.0 and won’t work on older systems.

各版本下載點

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

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


1.0 | 1.0.1 | trunk |

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

  • oAuth Twitter Feed for Developers 》一個符合 Twitter API 1.1 規範的 WordPress 外掛,為主題開發人員提供從 Twitter 使用者時間線取得物件陣列的功能。, 新的 Twitter API 需要您進行 oAuth 認...。
  • Simple Twitter Tweets 》一個簡單的 Twitter 儀表板外掛,使用 Twitter OAth 和 API v1.1,並備份以確保始終顯示您的 Tweets。, 為什麼要使用這個外掛?, 我們的客戶,尤其是共享主機...。
  • Advanced Social Feeds Widget & Shortcode 》Facebook & Twitter Integration 外掛是用來在您的網站上展示您的品牌 Facebook & Twitter 檔案的小工具,以增加您的 Facebook 專頁讚數及 Twitter ...。
  • Customize Feeds for Twitter 》Customize Feeds for Twitter 是一個 WordPress 外掛,可以使用 shortcode 或 widget 在你的網站上即時顯示 Twitter 動態。, 它完全可自定義,可以展示網站風...。
  • TweetScroll Widget 》TweetScroll 是一個使用新的 oAuth API 1.1 顯示您的 Twitter 帳戶最新推文的小工具。, 此簡單的小工具可用於任何網站/部落格。, Twitter 最近關閉了他們的 A...。
  • Tweeple 》對於所有推客,這是適合您的外掛程式。當然,已經有數量繁多的 Twitter WordPress 外掛程式,但 Tweeple 可以給您更 ThemeBlvd 風格的解決方案。, 注意:此外...。
  • Slim Jetpack 》Jetpack 是 Automattic 提供的一個超強的 WordPress 外掛套裝,但使用它需要 WordPress.com 帳戶,即使以前這些模組是獨立的外掛。此外,其行銷橫幅也非常惱...。
  • Display Tweets 》Display Tweets 是一個非常簡單易用的 Twitter feed 外掛,您可以使用 shortcode、PHP 函數或 widget 來顯示您的推文。它完全是面向未來設計,並使用驗證請求...。
  • Wickett Twitter Widget 》在 WordPress 小工具中顯示您的 Twitter 帳戶中的最新推文。使用您網站或主題的 CSS 自訂推文顯示。, 自訂顯示的推文數量。從顯示的推文中過濾 @ 回覆。可選...。
  • Twiget Twitter Widget 》Twiget Twitter Widget 可讓您在任何小工具區域顯示您的最新 Twitter 狀態更新。只需將 Twiget Twitter Widget 加入側邊欄或任何小工具區域,輸入您的 Twitte...。
  • Arrow Custom Feed for Twitter 》首頁 | 演示 | 支援 | 高級版, Twitter Feed by ArrowPlugins 是一款用於 WordPress 的高級 Twitter Feed 外掛程式。您可以透過這個外掛程式將 Twitter Feeds...。
  • Peadig's Twitter Feed: Embedded Timeline WordPress Plugin 》WordPress Twitter Feed 外掛讓您能輕鬆地將任何用戶的推文輸出到 WordPress 頁面、模板或側邊欄!您可以自訂使用者名稱、推文數量,以及輸出的樣式。, , Twi...。
  • Mini twitter feed 》重要通知:Twitter已關閉其v1 API並現在使用v1.1,要更新您的小型Twitter Feed,您需要前往https://twitter.com/settings/widgets/new創建一個新的小工具,並...。
  • Ultimate Twitter Feeds 》Ultimate Twitter Feeds是最好的輕量級外掛之一,可在您的網站上顯示Twitter feeds(推文)。它可以從Twitter個人檔案、Twitter用戶列表和單個推文中提取feed...。
  • FireCask’s Twitter Follow Button 》快速添加 Twitter 追蹤按鈕的外掛。可以輕鬆地實現在您的頁面、文章或佈景主題模板中。, , Twitter Follow Button WordPress 外掛主頁。, 更多的 WordPress ...。

文章
Filter
Apply Filters
Mastodon