开发者 | dartiss |
---|---|
更新时间 | 2010年10月20日 23:20 |
捐献地址: | 去捐款 |
PHP版本: | 2.0.0 及以上 |
WordPress版本: | 3.0.1 |
<a href="<?php simple_twitter_link(''); ?>">Send to Twitter</a>
This will display the text "Send to Twitter" on your page/post. However, when clicked on it will take you to your Twitter account and pre-fill in the status with "I'm currently reading xxx", where xxx will be the URL of the page/post that you just came from.
In the case of this example, no parameters were passed and, hence, a default sentence was passed to Twitter. If, however, you'd like to define your own Twitter text, then you simply pass this as a parameter. %url%
must be specified within the sentence, as this tells Simple Twitter Link where you want the URL to go.
So, another example...
<a href="<?php simple_twitter_link('%url% is an excellent read'); ?>">Send to Twitter</a>
In this case the line "xxx is an excellent read" (again, where xxx is the URL of your page/post) will be passed to Twitter.
If you don't pass a parameter or miss out the %url% tag the default text will be used.
The following is an example of how it could be used, with a function_exists
check so that it doesn't cause problems if the plugin is not active...
<?php if (function_exists('simple_twitter_link')) : ?>
<a href="<?php simple_twitter_link(''); ?>">Send to Twitter</a>
<?php endif; ?>
You can also use an addition tag, %title%
, which will show the post/page title in the Twitter text.
If you have the Simple URL Shortener plugin installed, you can also use a number of additional tags which will allow the URL to be shortened. Simple specify the name of the shortening service withing percentage signs within the Twitter text (this text will then be removed from the resultant output to Twitter). So, here is a further example...
<a href="<?php simple_twitter_link('%tr.im%Currently reading a blog post called "%title%" - %url%'); ?>">Send to Twitter</a>
This uses both the new %title% tag and also uses the tr.im shortening service to shorten the URL.
By default, the URL of the current post/page is used. If, however, you specify a URL as a second parameter then this will be used instead (useful if you wish to add a generic Twitter link to your sidebar, for instance). An example would be...
<a href="<?php simple_twitter_link('%tr.im%Currently reading a blog post called "%title%" - %url%','http://www.artiss.co.uk'); ?>">Send to Twitter</a>
From version 1.6 onwards you can also specify a number of further options via an optional third parameter. Each option is seperated by an ampersand and the following are valid...
cache= : Use this to turn off caching by specifying cache=no
apikey=, login=, password= : These allow optional URL shortening options to be specified (see the documentation for Simple URL Shortener for further details)
For example,
<a href="<?php simple_twitter_link('%bit.ly+key%Currently reading a blog post called "%title%" - %url%','','login=test&apikey=insertapikeyhere&cache=no'); ?>">Send to Twitter</a>
In this case you'd need to specify your own login and apikey for this to work.
There is an excellent article on how to use this plugin at Blogging With Success.
simple-twitter-link
folder to your wp-content/plugins/
directory.= I get the error “cannot yet handle MBCS in html_entity_decode” This is a known bug in PHP 4. If other solutions do not work don’t request the “title” option in this plugin, as it is this that will trigger it. Feel free to report any problems, or suggestions for enhancements, to me either via my contact form or by the plugins homepage.
%title%
, which will show the post/page title in the Twitter text%is.gd%
, %snipr%
, %tr.im%