2012-06-11 85 views
15

我想知道是否有一种方法为Facebook,Twitter和Google +1创建“分享”按钮,而不使用任何Javascript必须在任何时候插入代码中。仅使用HTML(无Javascript)的Facebook,Twitter和Google +1按钮

例如,您可以使用下面描述的方法动态创建这些按钮;但他们都最终动态加载Javascript和建立在幕后自己的代码:

回答

24

以下链接将注册相应的喜欢,推文和+ 1s:

这些链接将WordPress的工作:

的Facebook

<a href="http://www.facebook.com/sharer.php?u=<?php if(is_home()){echo home_url();}else{the_permalink();} ?>" target="_blank" title="Share this page on Facebook">Like</a> 

Twitter的

<a href="http://twitter.com/share?url=<?php if(is_home()){echo home_url();}else{the_permalink();} ?>&text=<?php the_title(); ?>" target="_blank" title="Tweet this page on Twitter">Tweet</a> 

谷歌+1

<a href="https://plusone.google.com/_/+1/confirm?hl=en&url=<?php if(is_home()){echo home_url();}else{the_permalink();} ?>" target="_blank" title="Plus one this page on Google">+1</a> 
+0

请问Facebook网址采取任何更多的PARAMS?或者它只是'你'? – henrywright

+0

@henrywright看来Facebook现在更喜欢不同的语法;答案中的URL有效,但这里有更多关于如何使用共享对话框的信息:https://developers.facebook.com/docs/sharing/reference/share-dialog#redirect关于遗留网址的选项,看到这篇文章:http://ar.zu.my/how-to-really-customize-the-deprecated-facebook-sharer-dot-php/ –

+0

感谢您的跟进。我会看看链接... – henrywright

6

谷歌加在上面的例子中不能正常工作。

我用这个谷歌加。

<div id="custom-google-button"> 
    <a href="https://plus.google.com/share?&hl=en&url=YOUR_URL_to_share" target="_blank">google+</a> 
</div> 

在WordPress:

<a href="https://plus.google.com/share?hl=en&url=<?php if(is_home()){echo home_url();}else{the_permalink();} ?>" target="_blank" title="Plus one this page on Google">google+</a> 

LinkedIn:

<div id="custom-linkedin-button"> 
    <a href="http://www.linkedin.com/shareArticle?mini=true&url=YOUR_URL_to_share" target="_blank">Linkedin</a> 
</div> 

在WordPress:

<a href="http://www.linkedin.com/shareArticle?mini=true&url=<?php if(is_home()){echo home_url();}else{the_permalink();} ?>" target="_blank">Linkedin</a> 

来源:

2

这是提供您正在寻找的答案,而无需使用任何PHP一个非常有用的文章 - http://www.hanselman.com/blog/AddSocialSharingLinksToYourBlogWithoutWidgetJavaScript.aspx

TWITTER

<a href="https://twitter.com/intent/tweet?url=YOURURLHERE&text=YOURPOSTTITLEHERE&via=YOURTWITTERNAMEHERE">Twitter</a> 

FACEBOOK

<a href="https://facebook.com/sharer.php?u=YOURURLHERE">Facebook</a> 

GOOGLE +

<a href="https://plus.google.com/share?url=YOURURLHERE">Google+</a> 
相关问题