| 开发者 | dartiss |
|---|---|
| 更新时间 | 2012年11月1日 22:35 |
| 捐献地址: | 去捐款 |
| PHP版本: | 2.0 及以上 |
| WordPress版本: | 3.4.2 |
[twitter user="username" data="dataitem"]
Where username is the Twitter username and dataitem is the data item that you require (as per the list above).
There is an additional parameter of cache. Twitter data is cached locally for a number of hours - use this option to specify the number of hours that a cache should be used for. The default is 0.5. Specify NO to switch off caching.
For example, to output the latest Tweet for artiss_tech and to cache it for 1 hour you would put in a post...
[twitter user="artiss_tech" data="status" cache=1]
Using the PHP Function Call
To grab Twitter data you will need to insert the following code, where appropriate, into your theme…
<?php get_twitter_profile( 'paras' ); ?>
Where paras is a list of parameters each separated by an ampersand...
user= : This is the Twitter username
data= : This is the list of Twitter data that you wish to have returned. Each data item must be separated by a comma and should be from the list above.
cache= : Twitter data is cached locally for a number of hours - use this option to specify the number of hours that a cache should be used for. The default is 0.5. Specify NO to switch off caching.
The following 2 parameters are only relevant to any links contained with a returned Tweet (by default all Tweets will be HTML character encoded and URLs will have links)...
nofollow= - If specified as ON this will turn on the NOFOLLOW attribute for the links. By default, this is switched off.
target= - Allows you to override the standard TARGET of _BLANK.
The Twitter data is returned in an array with the data item being the array element.
So, let's say you want to grab the name and Tweet for artiss_tech...
<?php $return_data = get_twitter_profile( 'user=artiss_tech&data=name,status&cache=1' ); ?>
This asks for the name and status of the user 'artiss_tech' and makes it cache the results for 1 hour. $return_data[ 'name' ] will now contain the name and $return_data[ 'status' ] will contain the status.
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( 'get_twitter_profile' ) ) { $return_data = get_twitter_profile( 'user=artiss_tech&data=name,status&cache=24' ); } ?>
Get URL References
There is an additional PHP function which will return the number of times a URL has been referenced. This will work with shortened URLs as well, so the count will reflect the resultant URL, not the shortened version. The format is...
<?php get_twitter_count( 'url', 'paras' ); ?>
Where url is the URL that you wish to return a count for and paras is a list of additiona parameters, each seperate by an ampersand. However, at the moment there is only one parameter...
cache= : URL reference data is cached locally for a number of hours - use this option to specify the number of hours that a cache should be used for. The default is 0.5. Specify NO to switch off caching.
Options Screen
Within Administration and under the Options menu, there is a sub-menu option named "Twitter Data". Selecting this allows you to specify a number of default values (namely the cache length and twitter user).
If you don't specify either of these in the shortcode/PHP function then the value from this screen will be used instead.
simple-twitter-datafolder to your wp-content/plugins/ directory.It has been tested and been found valid from PHP 4 upwards. Please note, however, that the minimum for WordPress is now PHP 5.2.4. Even though this plugin supports a lower version, I am not coding specifically to achieve this - therefore this minimum may change in the future.
Each field has to be found in the XML returned from Twitter - the more you request the more time it takes the plugin. Therefore requesting ONLY those that you require ensures maximum plugin efficiency.
You can also use the shortcode [twitter-data] - it works just the same as [twitter] with the same parameters.