Community Documentation

Theming Twitter views

Last updated November 19, 2011. Created by miahawk on March 24, 2009.
Edited by steinmb, webchick, quicksketch. Log in to edit this page.

Using Twitter module with Views2 on a membership site and needed a way to link back to members on Twitter, so wrote this views-view-fields--tweet.tpl.php override that links each tweet back to site member's Twitter account:

<div class="twitter_users_picture">
<a href="http://www.domain.com/<?php print $row->users_name; ?>"><img src="http://www.domain.com/<?php print $row->users_picture; ?>" /></a>
</div>

<div class="twitter_users_name">
<a href="http://www.domain.com/<?php print $row->users_name; ?>"><?php print $row->users_name; ?></a> says:
</div>

<div class="twitter_text">
<?php print $row->twitter_text; ?>
</div>

<div class="twitter_created_time">
Tweeted <?php print format_date($row->twitter_created_time); ?>
</div>

<div class="twitter_screen_name">
<a href="http://www.twitter.com/<?php print $row->twitter_screen_name; ?>">Follow <?php print $row->twitter_screen_name; ?> on Twitter</a>
</div>

I'm not a programmer or themer, so there are probably better ways to do this but it solved some output formatting issues for me. I'm not good enough to get the @names in the tweets to link, although it would be nice!

Comments

Making @names and links work

Hi!

You can try and integrate this to the module... it turns urls in tweets into proper linked urls and also the @whoever into proper links too...

I've tested it and it works stand alone and also in Wordpress - In Drupal not tested yet because of caching issues in my original code. Full working version (standalone) available here - http://hygen.net/blog/?p=536

<?php
$PrintMe
= $Variable_Containing_Twitters_Text;
$PrintMe = url2link ($PrintMe);
$PrintMe preg_replace("/@([A-Za-z0-9_]+)/","<a href='http://www.twitter.com/$1'>$0</a> ",$PrintMe) . '';
print
$PrintMe;

       
       
/* Functions */
       
       
function reduceurl($url, $url_length) {
       
$reduced_url = substr($url, 0, $url_length);
        if (
strlen($url) > $url_length) $reduced_url .= '...';
        return
$reduced_url;
        }
        function
url2link($linktext) {
       
$linktext = preg_replace("#(([a-zA-Z]+://)([a-zA-Z0-9?&%.;:/=+_-]*))#e", "'<a href=\"$1\">' . reduceurl(\"$3\", 25) . '</a>'", $linktext);
        return
$linktext;
        }
?>

Dan Gibas, HYGEN

Is this solution also

Is this solution also available for Drupal 7 with Views 3?

neofelis - Internet-agency for Webdevelopment and Internet-Marketing
Visit us on http://www.neofelis.de

Page status

Needs technical review

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Designers/themers
Level
Intermediate

Site Building Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here