<code>
Please go through the following steps to display the select list as year links
//hook_theme
function mymodule_theme($existing, $type, $theme, $path){
return array(
'list_items' => array(
'template' => 'list_items', //tpl to display them as list
'path' => $path . '/templates',
'type' => 'module',
'variables' => array(
'list' => NULL,
'current' => NULL
),
),
);
}
/*
hook_form_alter
*/
function mymodule_form_alter(&$form, &$form_state, $form_id) {
if($form_id == 'views_exposed_form') {
$current = '';
$ranges = explode(':',$form['date_filter']['value']['#date_year_range']);
foreach($ranges as $key => $range) {
$ranges[$key] = date('Y', strtotime($range.' years', strtotime(date('Y-m-d H:i:s'))));
}
$startYear = $ranges[0];
$endYear = $ranges[1];
if($ranges[0] > $ranges[1]) {
$endYear = $ranges[0];
$startYear = $ranges[1];
}
$items = array();
$endYear = (int)$endYear;
$startYear = (int)$startYear;
if(empty($_REQUEST['date_filter']['value']['year'])) {
$items[] = 'All years';
} else {
$items[] = l('All years', current_path(),array('query' => array("date_filter[value][year]" => '')));
}
for($i=$endYear; $i>=$startYear; $i--) {
if($_REQUEST['date_filter']['value']['year'] == $i) {
$items[$i] = $i;
} else {
$items[$i] = l($i, current_path(), array('query' => array("date_filter[value][year]" => $i)));
}
}
$list = theme('list_items', array('list' => $items, 'current' => $_REQUEST['date_filter']['value']['year']));
$form['html'] = array(
'#type' => 'markup',
'#markup' => $list,
);
}
}
/*
templates/list_items.tpl.php
*/
<ol><?php foreach($list as $key => $value) { if($current == $key || empty($current)) { ?><li class="active"><?php print $value; ?></li>
<?php } else { ?> <li><?php print $value; ?></li>
<?php } } ?></ol>
//mymodule.info
name = Filters customization
description = Filters customization
version = VERSION
core = 7.x
dependencies[] = date
</code>
謝謝 - 好的提示,我會沿着這個方向。 – 2010-01-31 13:12:32