显示多个推特分享按钮

Showing multiple twitter share buttons?

本文关键字:分享 按钮 显示      更新时间:2023-09-26

在我的网站的某个页面上,用户有一个项目列表,如下所示:

<div id="item1">.....</div>
<div id="item2">.....</div>
<div id="item3">.....</div>

这些div中的每一个在我的网站上都有一个自己的特殊链接,例如:

example.com/items/1
example.com/items/2
example.com/items/3

我想在每个单独的div中显示一个Twitter共享按钮,单击该按钮时,将允许用户将该特定项目的URL推到他们的Twitter上。

有没有插件可以做到这一点?

不需要第三方插件。使用Twitter插件:

<!DOCTYPE html>
<html lang="de">
  <head>
    <!-- meta -->
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="robots" content="noindex, nofollow">
    <title>Twitter Share Buttons</title>
  </head>
  <body>
    <div id="item1"><a href="https://twitter.com/share" class="twitter-share-button" data-url="http://example.com/items/1" data-text="Text to share 1">Tweet</a></div>
    <div id="item2"><a href="https://twitter.com/share" class="twitter-share-button" data-url="http://example.com/items/2" data-text="Text to share 2">Tweet</a></div>
    <div id="item3"><a href="https://twitter.com/share" class="twitter-share-button" data-url="http://example.com/items/3" data-text="Text to share 3">Tweet</a></div>
    <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
  </body>
</html>