weboftalent / twitter-tools
使用短代码嵌入推文。可选地将Twitter卡添加到页面中。
Requires
This package is auto-updated.
Last update: 2024-09-05 12:21:06 UTC
README
## 简介 此模块提供以下功能
- 使用短代码嵌入推文
- 可选地包含一个脚本以放大嵌入推文中的图片,以便您可以使用比Twitter的正常最小宽度更大的图片
- Twitter卡可以是任何扩展Page的类型,前提是实现了一个接口。
整合Twitter
<% require javascript("weboftalent/twitter_tools: javascript/render-twitter-embeds.js") %>
##Embedding Tweets
Tweets can be embedded into content using a shortcode like the following - the id parameter is the id of the tweet.
[tweet id='537136515445710848']
## Enlarging Embedded Images
**** 需要重新测试 ****
A script is included that you can include in your theme (either using require_javascript or a direct
script include in the template) called twitteruril.js - include this and larger (at source size,
perhaps not theme size) embedded images will render on your site.
## Twitter Cards
In order for a page to render an title, description and image when included as a link in a tweet, it needs provide metadata known as a Twitter Card. There are two steps to take in order to achieve this:
### Implement RenderableAsTwitterCard Interface
A minimal example of a class implementing a Twitter card is shown below.
class PageWithImage extends Page implements RenderableAsTwitterCard { private static $db = array( 'ImageAttribution' => 'Varchar(255)', 'BriefIntroduction' => 'Text' );
static $has_one = array( 'MainImage' => 'Image' );
// 实现Twitter卡接口 public function getTwitterTitle() { return $this->Title; }
public function getTwitterImage() { return $this->MainImage(); }
public function getTwitterDescription() { return $this->BriefIntroduction; }
}
### Template Changes
In your page template, add the following to inside <head></head> section of your page:
```txt
<% include TwitterSummaryCardLargeImage %>
这将检查当前页面是否实现了RenderableAsTwitterCard接口。如果是,它将为Twitter渲染Twitter卡生成相关元数据。
使用卡验证器测试
使用Card Validator测试您的Twitter卡,https://cards-dev.twitter.com/validator 在您网站的公开版本上 - 这将突出显示任何问题。还应注意的是,您的网站可能需要白名单。
待办事项
- 跟随按钮的短代码,允许内容编辑器将其内联添加。
- 允许不同类型的TwitterCard,并使其可配置。