2

我试图想出一种在 Drupal 视图中建立颜色编码的方法。我对此有几个需求,但不知道该怎么做。这里有些例子...

  1. 在内容类型的表格视图中,我想根据帖子的年龄对每一行进行颜色编码。换句话说,帖子的“年龄”是表格中的一列,我希望帖子不到一天的每一行都以黄色背景突出显示。如果超过一周,则用红色突出显示,依此类推...

有人对此有想法吗?我怀疑我们可能会在普通网页中获取条件值,但这在 Drupal 中很棘手,而且我的 javascript 知识有限。我知道通过良好的 ole SQL 我们可以在值上运行一些 PHP 并关联一个 css 选择器来执行此操作,但我试图在视图中完成它(贡献的模块)。提前致谢

4

1 回答 1

1

我将创建一个 views-view-table--Temp.tpl.php(其中 Temp 是视图名称),根据日期插入到类中。这是一个示例,我将创建的日期更改为显示 Time Ago,并使用 stripos 在 Week 或 Day 上进行搜索。您可以使用 php date math 或其他方法来插入您的课程。这是非常基本的,需要调整:

<?php
// $Id: views-view-table.tpl.php,v 1.8 2009/01/28 00:43:43 merlinofchaos Exp $
/**
 * @file views-view-table.tpl.php
 * Template to display a view as a table.
 *
 * - $title : The title of this group of rows.  May be empty.
 * - $header: An array of header labels keyed by field id.
 * - $fields: An array of CSS IDs to use for each field id.
 * - $class: A class or classes to apply to the table, based on settings.
 * - $row_classes: An array of classes to apply to each row, indexed by row
 *   number. This matches the index in $rows.
 * - $rows: An array of row items. Each row is an array of content.
 *   $rows are keyed by row number, fields within rows are keyed by field ID.
 * @ingroup views_templates
 */
?>
<table class="<?php print $class; ?>">
  <?php if (!empty($title)) : ?>
    <caption><?php print $title; ?></caption>
  <?php endif; ?>
  <thead>
    <tr>
      <?php foreach ($header as $field => $label): ?>
        <th class="views-field views-field-<?php print $fields[$field]; ?>">
          <?php print $label; ?>
        </th>
      <?php endforeach; ?>
    </tr>
  </thead>
  <tbody>
    <?php foreach ($rows as $count => $row): ?>
      <tr class="<?php print implode(' ', $row_classes[$count]); ?> <?php
        if(stripos($row["created"], "Week")) {
                print "week-class ";
        }
        if(stripos($row["created"], "Day")) {
                print "day-class ";
        }?>
        ">
        <?php foreach ($row as $field => $content): ?>
          <td class="views-field views-field-<?php print $fields[$field]; ?>">
            <?php print $content; ?>
          </td>
        <?php endforeach; ?>
      </tr>
    <?php endforeach; ?>
  </tbody>
</table>
于 2010-01-12T19:18:28.103 回答