How to add rel attribute to image link in Drupal 7

Here is a standart field.tpl.php file wich we can find using path: root/modules/field/theme.

{syntaxhighlighter brush: css;fontsize: 100; first-line: 1; }<div class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>> <?php if (!$label_hidden): ?> <div class="field-label"<?php print $title_attributes; ?>><?php print $label ?>:&nbsp;</div> <?php endif; ?> <div class="field-items"<?php print $content_attributes; ?>> <?php foreach ($items as $delta => $item): ?> <div class="field-item <?php print $delta % 2 ? 'odd' : 'even'; ?>"<?php print $item_attributes[$delta]; ?>><?php print render($item); ?></div> <?php endforeach; ?> </div> </div>{/syntaxhighlighter}

Inside foreach loop we insert just one line before any other and we get what we need.

{syntaxhighlighter brush: css;fontsize: 100; first-line: 1; } <?php $item['#path']['options'] += array('attributes' => array('rel' => $element['#field_name'])); ?>{/syntaxhighlighter}

If we add rel attribute in order to implement fancybox gallerry we should note that all images with the same rel attribute wil have navigation between each other inside gallery window.

10 out of 10 based on 1 ratings.