Textpattern tips, tutorials and code snippets

Create a friendly invite to Tweet your articles

The Twitter service is more popular than ever today. This simple code will render an invitation to Tweet your articles and display a pre-formated TinyUrl link within Twitter.

In your article form or page template:

<p><a href="http://twitter.com/home?status=Je%20lis%20%3Ca%20href='<txp:php>echo file_get_contents("http://tinyurl.com/api-create.php?url=".permlink(array())).'\'%3E'.$thisarticle['url_title'];</txp:php>%3C/a%3E" title="Publiez sur Twitter!" class="tooltip" onclick="window.open(this.href); return false;">Tweet!</a></p>

Add the code to your article form or page template, and your visitors will see a Twitter icon which when clicked will result in a Tweet that looks like so:

I am currently reading <a href='http://tinyurl.com/XXXXXX'>your_TXP_article_title</a>

Please note that if you want to display a Twitter icon, you will need to download and store the image in a folder called /img in your web root, otherwise you will need to edit the code above.

Twitter
Tweet from a Textpattern article link
Use Textile help to style your comments