Drupal Views conditional link
Using views and Views custom field...I want a link to change depending on if a file was uploaded [upload_fid-path], or if a URL [field_url_url] was given.
If a file was uploaded that takes precedance over the URL...If no file is attached, than link to the URL...If no URL exist, then link to node.
Any help wou开发者_如何转开发ld be appreciated, thanks!
Add file field in views.
Add Customfield: PHP code, enter there code:
<?php
print '<pre>'.print_r($data).'</pre>';
?>
you will see internal of data, filled like:
stdClass Object
(
[nid] => 46
[node_type] => consignment
[node_vid] => 53
[node_data_field_cnsgm_image_field_cnsgm_image_fid] => Array
(
[0] => Array
(
[fid] => 47
[list] => 1
[data] => a:3:{s:11:"description";s:10:"Test descr";s:3:"alt";s:0:"";s:5:"title";s:0:"";}
)
[1] => Array
(
[fid] => 57
[list] => 1
[data] => a:3:{s:11:"description";s:0:"";s:3:"alt";s:0:"";s:5:"title";s:0:"";}
)
)
)
node_data_field_cnsgm_image_field_cnsgm_image_fid for current example is file field representation, fid is reference to {files} table, there you can get path to filepath of file.
So you need to check this field to show what you want...
p.s. You field will be difference. Be carefull, $data column names will changed if you add new fields in views, so need to add you custom field at last time...
Use views conditional module, this will help you to create if else statement. Only for drupal 7
Ref: https://drupal.org/project/views_conditional
精彩评论