3
votes

I'm trying to create a page by using view 2. This page list all the nodes and grouping by their taxonomy term. In this view the Style as Unformatted and Row style as Fields. The fields as following:

Node: Title 
Node: Teaser 
Taxonomy: Term 

The problem is that I want the first row under each term display both Title & Teaser and the rest display only the Title. Example:

-News

  1. Title & Teaser
  2. Title
  3. Title

-Sport

  1. Title & Teaser
  2. Title
  3. Title

-Entertainment

  1. Title & Teaser
  2. Title
  3. Title

I tried to theme by using

  • views-view-unformatted.tpl.php
  • views-view-fields.tpl.php
  • views-view-field.tpl.php

above three files with no luck. I have struggled with this issue for a while now, any help will be appreciated. Thank you.

4

4 Answers

4
votes

You'll need to use the 'Row style output' template (e.g. views-view-fields.tpl.php).

To make it unique to your view, you'll want to use a more specific template name than that, such as the last possible template name showed in that section - e.g. views-view-fields--myview--default.tpl.php.

Once there, you'll need you have a global variable to keep track of the current row, something like:

<?php 
  global $is_first_of_term;

  if(!isset($is_first_of_term)){
    $is_first_of_term = TRUE;
  } else {
    $is_first_of_term = FALSE;
  }


  // Then use $is_first_of_term below (unmodified original script)
  // to print whatever you want.
?>
<?php foreach ($fields as $id => $field): ?>
  <?php if (!empty($field->separator)): ?>
    <?php print $field->separator; ?>
  <?php endif; ?>

  <<?php print $field->inline_html;?> class="views-field-<?php print $field->class; ?>">
    <?php if ($field->label): ?>
      <label class="views-label-<?php print $field->class; ?>">
        <?php print $field->label; ?>:
      </label>
    <?php endif; ?>
      <?php
      // $field->element_type is either SPAN or DIV depending upon whether or not
      // the field is a 'block' element type or 'inline' element type.
      ?>
      <<?php print $field->element_type; ?> class="field-content"><?php print $field->content; ?></<?php print $field->element_type; ?>>
  </<?php print $field->inline_html;?>>
<?php endforeach; ?>
0
votes

Setup each view display as 'content pane'. Use a panel (panels3 module) with multiple views, first view has title and teaser (limit 1), next view is just titles (limit 2 or 3). You can 'stack' multiple views in the same panel.

Repeat for each taxonomy; use taxonomy for arguments.

0
votes

You should just be able to get the $id and see if its 1. EX:

<?php if (!empty($title)): ?>
  <h3><?php print $title; ?></h3>
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
 <?php if (%id == 1): ?>
  <?php print [items you want] ?>
 <?php endif; ?>
  <div class="<?php print $classes[$id]; ?>">
    <?php print $row; ?>
  </div>
<?php endforeach; ?>

The issue I am running into is that I want the global row number almost like what a pager would use so I can split based on 15 items per row. I can't for the life of me find that number though.

0
votes

Drupal's Display Suite module can help you do this. It gives you a lot of options for display mode configuration as well as a Display Suite view settings which will let you show the first item in your view using one display configuration and subsequent items using another. You can alternate if you wanted to too but that's not what you're asking.

The big upside to this implementation is that you can do it all from configuration and not have to touch any PHP.

Check out a tutorial I found about this here: http://clikfocus.com/blog/changing-views-output-based-row for information on how to do this.