Skip to content

Instantly share code, notes, and snippets.

View frankyonnetti's full-sized avatar

Frank Yonnetti frankyonnetti

View GitHub Profile
@frankyonnetti
frankyonnetti / drupal7-print-field.php
Last active February 17, 2021 03:51
Drupal 7 - print field #drupal #d7
// better
<?php $services = field_get_items('node', $node, 'field_services'); ?>
<?php if($services): ?>
<?php print render($content['field_services']); ?>
<?php endif; ?>
// other
<?php $city = field_view_field('node', $node, 'field_city', array('label' => 'hidden')); print render($city); ?>
@frankyonnetti
frankyonnetti / drupal6-print-field.php
Last active February 17, 2021 03:51
Drupal 6 - print CCK field #drupal #d6
<?php if(isset($node->field_NAME[0]['value']) && $node->field_NAME[0]['value'] != ''): ?>
<div class="name">
<?php print $node->field_NAME[0]['value'] ?>
<!-- OR -->
<?php print content_format('field_NAME', $field_NAME[0]); ?>
</div>
<?php endif; ?>
@frankyonnetti
frankyonnetti / drupal6-image-field-path.php
Last active February 17, 2021 03:49
Drupal 6 - print cck image_field path #drupal #d6
<img src="/<?php print $node->field_self_photo[0]['filepath'] ;?>" alt="<?php print $node->field_self_photo[0]['data']['alt'] ;?>" />
@frankyonnetti
frankyonnetti / drupal6-cc-field-loop.php
Last active February 17, 2021 03:49
Drupal 6 - CCK field loop #drupal #d6
<?php if(isset($node->field_NAME[0]['value']) && $node->field_NAME[0]['value'] != ''): ?>
<div class="field-field-NAME"><div class="field-items">
<?php foreach ($field_NAME as $i => $NAME) { ?>
<?php if ($i != 0):?> | <?php endif; ?>
<?php print content_format('field_NAME', $NAME); ?>
<?php } ?>
</div></div>
<?php endif; ?>
@frankyonnetti
frankyonnetti / drupal-display-field-names.php
Last active February 17, 2021 03:48
Drupal - display field names and array #drupal
<?php // display all
dsm(get_defined_vars());
?>
<?php //http://drupal.org/node/308732
print '<pre>';
var_dump(get_defined_vars());
print '</pre>';
?>
@frankyonnetti
frankyonnetti / drupal7-views-count-rows.php
Last active February 17, 2021 03:47
Drupal 7 - views count rows #drupal #d7
<?php
for ($i = $view->total_rows + 1; $i <= 4; $i++) {
print '<div class="events ' . $i . '">';
print ' <h3>No Events</h3>';
print '</div>';
}
?>
@frankyonnetti
frankyonnetti / multiple_user_roles.php
Last active May 23, 2021 18:41
#drupal checked if logged in / role
<?php
global $user;
$has_role = array_intersect(array('administrator', 'Other admin', 'Client admin'), array_values($user->roles));
if (empty($has_role) ? FALSE : TRUE) {
// This user has any one of the three roles
}
?>
@frankyonnetti
frankyonnetti / drupal7-remove-all-day.php
Last active February 17, 2021 03:46
Drupal 7 - remove (All day) label #drupal #d7
<?php // Add to template.php
function [theme name]_date_all_day_label() {
return '';
}
@frankyonnetti
frankyonnetti / drupal7-if-node-type.php
Last active May 22, 2021 19:22
Drupal 7 - check if node->type #drupal #d7
<?php if ($node->type == 'content_type_name'): ?>
Do something...
<?php endif; ?>
@frankyonnetti
frankyonnetti / drupal7-comments-homepage-field.php
Last active February 17, 2021 03:44
Drupal 7 - remove homepage field in comments #drupal #d7
<?php
/**
* Remove homepage field in comments in template.php
* http://www.digett.com/blog/05/26/2011/how-theme-comment-form-drupal-7
*/
function THEMENAME_form_comment_form_alter(&$form, &$form_state) {
$form['author']['homepage']['#access'] = FALSE;
}
?>