我正在尝试以编程方式在页面上的iframe中包含推文按钮。我希望这可以发布特定帖子的wordpress短链接。
我正在使用PHP在我的wordpress数据库中插入以下HTML iframe代码以包含weet按钮。代码看起来像这样
'<iframe allowtransparency="true" frameborder="0" scrolling="no"
src="https://platform.twitter.com/widgets/tweet_button.html
?count=horizonatal?url=http://www.mywebsite.com?p= '
. $post_id . '"></iframe>'
正如你所看到的那样,我正在连接PHP代码中的$ post_id,以及wordpress短链接“http://www.mywebsite.com?p=”的其余部分。问题似乎是twitter小部件解释'?'在我的url属性中作为自身的查询 - 而不是对我的wordpress网站的查询 - 而且发生的事情是我只能发送http://www.mywebsite.com推文。
有没有人知道解决这个问题?
答案 0 :(得分:0)
您需要使用urlencode:
'<iframe allowtransparency="true" frameborder="0" scrolling="no"
src="https://platform.twitter.com/widgets/tweet_button.html
?count=horizonatal?url='.urlencode('http://www.mywebsite.com?p='.$post_id)
.'"></iframe>'