Apr 4, 2010

Creating Redirect Page using Views& CCK in Drupal

If you have a drupal website with many affiliate links, you may want to hide those long affiliate links by using a redirect script. This tutorial tells you how to create a redirect page using Views & CCK module.
  • In Administer>Site building>Views, add a new View.
  • In the View type, select Node, and click Next button.
  • In basic settings, set the Style to HTML List.
  • In the Arguments, add Node: Nid.
  • In the Fields, add the CCK field that contains affiliate link you want to redirect. In this tutorial, we add a content field named "Content: DownloadUrl". After you added the field, when put the mouse over the link, you will find the name of the field which is at the end of url shown on the status bar. In this tutorial this field is called field_downloadurl_value.
  • Edit the Page display. In the page settings, set the Path to whatever you want. In this tutorial, the path is set to "go/download".
  • Save the views.
  • Overide your views templates:

    Create a file views-view-fields--YOURVIEWSNAME--page-1.tpl.php in your theme folder.
    (Please note you need to replace
    YOURVIEWSNAME with the name of your view.
    In views-view-fields--YOURVIEWSNAME--page-1.tpl.php file, you can access the affiliate link using the variable $fields["field_downloadurl_value"]->raw.  Use the following code to redirect your page to the affiliate link:

    drupal_goto($fields["field_
    downloadurl_value"]->raw);
    ?>

  • In your node template, use the link "/go/download/nid ?>" to replace the affiliate link. 

No comments:

Post a Comment