Kingzly’s blog

But I have no idea!

color taxonomy event in drupal calendar

with one comment


โจทย์มีอยู่ว่า ต้องการแสดงสีที่แตกต่างกันตามหมวดหมู่ใน event calendar ของ drupal
เลยเข้าไปคุ้ยใน drupal.org เจอ คอมเม้นต์นี้ เลยลองเอามาทำดูเป็นวิธีของคนขี้เกียจ
เพราะต้องอาศัย pathauto ช่วยด้วย แต่เว็บที่ต้องทำลงไว้อยู่แล้วก็เอามาใช้ได้เลย
โดย

  • copy ไฟล์ calendar-month-node.tpl.php ใน โฟลเดอร์ calendar ที่ module มาไว้ที่โฟลเดอร์ theme ของเรา
  • แก้ไขโดยเพิ่มส่วนที่ดึง taxonomy term ออกมา แล้วมาเขียนเป็น css class

    <div class="view-item view-item-<?php print $view->name ?>">
    <?php
    $class
    = 'calendar monthview type-' . $node->type;
    if (
    module_load_include('inc', 'pathauto') !== FALSE) {
    $full_node = node_load(array('nid'=>$node->nid));
    foreach (
    $full_node->taxonomy as $term) {
    $class .= ' taxonomy-' . drupal_strtolower(pathauto_cleanstring($term->name));
    }
    }
    ?>

    <div class="<?php print $class?>" id="<?php print $node->date_id ?>">
    <?php print theme('calendar_stripe_stripe', $node); ?>
    <?php foreach ($fields as $field): ?>
    <div id="<?php print $field['id']; ?>" class="view-field view-data-<?php print $field['id'] ?>">
    <?php if ($field['label']): ?>
    <div class="view-label-<?php print $field['id'] ?>"><?php print $field['label'] ?></div>
    <?php endif; ?>
    <?php print $field['data']; ?>
    </div>
    <?php endforeach; ?>
    </div>
    </div>
  • แล้วก็ไปเพิ่ม class เพื่อกำหนดสีที่จะแสดง เช่น
    .taxonomy-recommend {background:#e7ffcf;}
  • เสร็จเรียบร้อย ไม่เจ็บปวด แต่สวยงาม แฮ่~

Written by kingzly

November 11, 2009 at 12:47 pm

Posted in Uncategorized

Tagged with , , ,

One Response

Subscribe to comments with RSS.

  1. อย่างนี้ต้องร้องว่า “The Best”

    numvarn

    November 11, 2009 at 3:14 pm


Leave a Reply