I have a view that pulls in the titles from 3 different content types. One of these content types has a title that should link to an external website, the other 2 types have titles that link to nodes within the Drupal site. Is there a way I can set the Title field to handle links differently depending on what content type the title is from?
Answered thanks to Vlad below!! 🙂
This is the working code we are using in the views-view-fields--news--block.tpl.php template..
<?php if ($fields['type']->content == 'Event'): ?>
<a href="<?php print $fields['path']->content; ?>"><?php print $fields['title']->content; ?></a>
<?php endif; ?>
<?php if ($fields['type']->content == 'PATF News'): ?>
<a href="<?php print $fields['path']->content; ?>"><?php print $fields['title']->content; ?></a>
<?php endif; ?>
<?php if ($fields['type']->content == 'News Link'): ?>
//This link goes to _blank
<a href="<?php print $fields['field_link']->content; ?>" target="_blank"><?php print $fields['title']->content; ?></a>
<?php endif; ?>
Drupal 6
Node: TypetoFieldsBasic settingsgroup clickTheme: Informationand clickRow style outputRow style outputinto your theme file (should be named something likeviews-view-fields--viewsname.tpl.phporviews-view-fields--viewsname--viewsnamw.tpl.php) in your theme folder.Drupal 7
It’s pretty similar with difference that you can find
Theme: Informationin groupAdvancedand you have to addContent: Typein yourFieldsgroup.In your
views-view-fields--xxx--xxx.tpl.phpfile write something like:Improved code