It's a little plugin to display the latest Tweets from any public Twitter account.
Copy the tweet.php file to your site/plugins folder. You should make sure to enable caching. Otherwise the plugin will call the Twitter API on every page view and you might soon be blocked.
- Go to site/config/config.php to set c::set('cache', true);
- Make sure that site/cache is writable (change permissions to 0755)
You can add it to your templates like this:
<?php $tweets = tweets('getkirby') ?>
<ul class="tweets">
<?php foreach($tweets as $tweet): ?>
<li>
<a class="user" href="<?php echo $tweet->user()->url() ?>">
<img src="<?php echo $tweet->user()->image() ?>" />
<strong><?php echo $tweet->user()->name() ?></strong>
<small>@<?php echo $tweet->user()->username() ?></small>
</a>
<p><?php echo $tweet->text(true) ?></p>
<a class="date" href="<?php echo $tweet->url() ?>"><?php echo $tweet->date('h:i A - d M y') ?></a>
</li>
<?php endforeach ?>
</ul>
Set options like this:
<?php
$tweets = tweets('getkirby', array(
'limit' => 5,
'refresh' => 60*60*5
));
?>
Sets the number of returned tweets.
Disable or enable the cache. Caching the results is highly recommended. Otherwise the plugin will be super slow. You must make sure that site/cache
is writable (change permissions to 0755) You must also set c::set('cache', true); in site/config/config.php to enable the cache.
Show or hide replies you've tweeted, e.g. for users with a large number of replies that aren't interesting for the general public.
Set the cache expiry in seconds. By default it will be set to 20 minutes. After 20 minutes the plugin will fetch fresh data from the Twitter API.
$tweet->url()
The URL to the Tweet page on Twitter$tweet->text()
The text of the Tweet$tweet->date()
The timestamp when the Tweet has been posted$tweet->source()
The source, from which the Tweet has been posted$tweet->user()
The user object (see object attributes)
$tweet->user()->name()
The full name of the user$tweet->user()->username()
The Twitter username$tweet->user()->bio()
The Twitter bio$tweet->user()->url()
The URL to the user's Twitter page$tweet->user()->image()
The user avatar pic$tweet->user()->following()
The number of accounts the user is following$tweet->user()->followers()
The number of followers
Bastian Allgeier http://getkirby.com