2

This is my first time using a table to display a Views template. How do you access a specific field so you can reorder them one by one yourself? I have 3 fields I want to place but I want one of the fields field_house to come out first, followed by field_door and field_table. I'm also asking so I can wrap each one in their own class making it easier to layout.

2
  • 1
    I got it!! The reason why I couldn't get it to work was because I kept writing my code in the wrong place. Just delete the loop <?php foreach ($row as $field => $content): ?> and replace it with actual code: <?php print $row['field_house']; print $row['field_door']; print $row['field_table']; ?> and it worked! All this is of course still within the main loop <?php foreach ($rows as $count => $row): ?>.
    – enchance
    Commented Jun 12, 2011 at 17:12
  • 1
    @enhance you should post this as an answer so it's easy for others to see that you've solved it
    – Chaulky
    Commented Jun 13, 2011 at 22:45

2 Answers 2

1

@Chaulky it should be pretty easy to make the changes suggested by @enhance.

  • Take the views table template and copy it to your theme.
  • Make the edits to your copy of the template as per @enhance's directions.
  • Since you mentioned adding classes, you could either add the classes in the template or in the views interface.
  • Save it as views-view-table-YOUR_VIEW_NAME.tpl.php.
  • Clear caches, at least twice if once didn't do it.
  • Continue theming and enjoy.
0

I'm late to this thread, but incase someone comes across it, here is example code that works.

I removed the code I didn't need from the Views tpl, and added the fields within the foreach loop.

<table <?php if ($classes) { print 'class="'. $classes . '" '; } ?><?php print $attributes; ?>>
  <tbody>
    <?php foreach ($rows as $row_count => $row): ?>
      <tr <?php if ($row_classes[$row_count]) { print 'class="' . implode(' ', $row_classes[$row_count]) .'"';  } ?>>
        <td class="views-field views-field-title">
          <?php print $row['title']; ?>
        </td>
        <td class="views-field views-field-field-website-url">
          <?php print $row['field_website_url']; ?>
        </td>
      </tr>
    <?php endforeach; ?>
  </tbody>
</table>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.