Drupal Custom Content Type in a foreach loop

<?php $query = new EntityFieldQuery(); $query->fieldOrderBy('field_news_date', 'value', 'DESC'); $query->entityCondition('entity_type', 'node') ->entityCondition('bundle', 'news') ->propertyCondition('status', 1); $result = $query->execute(); if (!empty($result['node'])) { $fielditems = field_get_items('node', $node, 'field_event_entity'); $nids = array_keys($result['node']); $individualitem = array_shift($fielditems); $entity = $individualitem['entity']; } ?> <?php $counter = 0; foreach ($nids as $nid): $counter++;?> <?php $node = node_load($nid, NULL, TRUE); // Format date $date = $node->field_news_date['und'][0]['value']; $date = strtotime($date); $date = date("l, F j", $date); $excerpt = $node->field_excerpt['und'][0]['value']; $pdf = $node->field_pdf_file['und'][0]['value']; ?> <div class="news-page-section"> <h5 class="views-field lines strong-date"> <?php echo($date);?> </h5> <h3 class="news-page-titles"><?php echo $node->title;?></h3> <div><?php echo($excerpt);?></div> <?php if(field_view_field('node', $node, 'field_pdf_file')): ?> <div class="field-content"><a href="<?php echo($pdf);?>" class="btn" target="_blank" data-thmr="thmr_166">Download PDF</a></div> <?php endif;?> <?php if(field_view_field('node', $node, 'field_news_link')): ?> <div class="field-content"><a href="<?php echo($link);?>" class="btn" target="_blank" data-thmr="thmr_166">Read Article</a></div> <?php endif;?> </div> <?php if( $counter % 3 == 0 ) echo '<div class="spacer"></div>'; ?> <?php endforeach; ?>
For each loop for custom content. In this particular case we are using a content type called news and we are echoing out data from four different fields. Make special not of the date formatting. No matter what setting I tried or date module Drupal always displayed the date in longer number format with the T00:00:00. This also uses a php modulus iterator to display div called spacer after every three entries. As an aside I would like to add that after using Drupal for the past three months, I'm glad the door to roof where I work is locked.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.