07/03/2011

Drupal 7: Mengubah Tipe Penanggalan

Drupal menyediakan empat tipe penanggalan: short, medium, long dan custom. Tipe medium merupakan default-nya. Sayang tak ada cara lebih mudah selain melalui pendekatan "theme override" untuk mengubahnya.

# Bila belum ada, reka file "template.php" di direktori induk theme terkait.

## Untuk node
# Salin "template_preprocess_node(&$variables)" dari file "modules/node/node.module" (sekitar baris ke-1440) ke dalam file "template.php".

# Cari dan ubah

$variables['date'] = format_date($node->created);

# menjadi (untuk tipe short, medium atau long)

$variables['date'] = format_date($node->created, '<tipe>');

# atau (untuk tipe custom)

$variables['date'] = format_date($node->created, '<tipe>', '<format>');

## Untuk comment
# Salin "template_preprocess_comment(&$variables)" dari file "modules/comment/comment.module" (sekitar baris ke-2263) ke dalam file "template.php".

# Cari dan ubah

$variables['created'] = format_date($comment->created);
$variables['changed'] = format_date($comment->changed);

# menjadi (untuk tipe short, medium atau long)

$variables['created'] = format_date($comment->created, '<tipe>');
$variables['changed'] = format_date($comment->changed, '<tipe>');

# atau (untuk tipe custom)

$variables['created'] = format_date($comment->created, '<tipe>', '<format>');
$variables['changed'] = format_date($comment->changed, '<tipe>', '<format>');

## Untuk semua
# Ubah <tipe> dan <format> sesuai selera.

# Demikian kira-kira ..

Catatan:
Untuk <tipe> pilih salah satu: short, medium, long atau custom.
Untuk <format> gunakan standard PHP.
Gunakan hanya tag pembuka PHP di dalam file template.php.

Bahan bacaan:
template_preprocess_node/7
template_preprocess_comment/7
format_date/7
en/function.date.php
node/1075692

0 comments:

Post a Comment