Community Documentation

Compute Twitter URL by collecting Twitter IDs

Last updated December 21, 2010. Created by chowdah on December 21, 2010.
Log in to edit this page.

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.

Comments

how to get value from url and

how to get value from url and pass it in computed field???...because get function is not workin!!
please help to solve my problem

This only provides a text

This only provides a text with a link to the twitter page? Why not just have a text field in the Directory Listing Content Type where you can enter the url for each Directory Listing content?

Then you can pull respective url based on node id as the argument.

About this page

Drupal version
Drupal 6.x
Audience
Contributors, Designers/themers, Programmers, Site administrators

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.