Menampilkan latest node di Drupal

Biasanya kite pengen menampilkan latest node di dalam block. Snippet berikut berdasarkan kode dari sini dengan sedikit modifikasi dimana tidak menggunakan fungsi theme, melainkan langsung meng echo secara barbar :)

<?php
// comma separated lists of terms tid to display nodes
$terms = "47,48,49,50";

// the number of nodes to show
$count = 5;

$sql = "SELECT DISTINCT n.title, n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid in ($terms) AND n.status=1 ORDER BY n.created DESC";
$result = db_query_range(db_rewrite_sql($sql), 0, $count);
if (db_num_rows($result)) {
  echo '<ul class="list">';
  while ($node = db_fetch_object($result)) {
    $link = 'node/'.$node->nid;
    echo '<li>'.l($node->title,$link).'</li>';
  }
  echo '</ul>';
}
?>

kalo mau bikin link misal read more ke term tertentu bisa menggunakan

<?php echo l('read more','taxonomy/term/47',array('class'=>'readmore')); ?>

utk detail penjelasan fungsi2 seperti l(), bisa diliat di API nya drupal

About Adi Setiawan

web developer, @startupbali initiator, ubuntu user, proud father. Living in-between space

04. December 2007 by Adi Setiawan
Categories: Drupal | Tags: , , | Leave a comment

Leave a Reply

Required fields are marked *

*