Compute Twitter URL by collecting Twitter IDs
I am creating a directory and added some fields for harvesting Social Media info - mainly Twitter and Facebook on a CCK content type called 'Directory Listing'. Most of the entities in the directory are organizations, companies, etc.
I had to harvest the entire Facebook page link, because their pages seem to follow some kind of archaic naming structure.
For Twitter, I wanted to harvest just the Twitter username because I would like to use it elsewhere as a token when making automated tweets by adding '@[token]' reference to the node title and url. So I collect the user name in a CCK field that is excluded from singular display and instead post the link to their Twitter Account embedded in a standardized link.
In CCK the field is a text field (widget type 'Text field') named 'field_twitter_username'. This is hidden from display, but is used as the base for the computed field called 'field_twitter_page_computed' which computes as follows:
//$node->field_twitter_username is the name of the CCK field that will be use to make the link
if ($node->field_twitter_username[0]['value']){
/*variablized this to make it more flexible in terms of changing the base path in the future if needed. I noticed 'Old Twitter' links were '/username' and 'New' (ca.12/2010) Twitter links are '/#!/username' */
$twitter_addy="http://www.twitter.com/";
//render the link while embedding the node title in the link's display text
$node_field[0]['value'] = "<a href=\"".$twitter_addy.$node->field_twitter_username[0]['value']."\" target=\"_twitter\">$node->title on Twitter</a>";
}
I then display 'field_twitter_page_computed' inline with it's label 'Twitter Page:'. The field is rendered in 'Raw text' style only in the full node.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion