Bạn cần tạo mô-đun nhỏ với các móc sau:
/**
* Implements hook_form_alter().
*
* Alter exposed filter form in views
*/
function MODULE_form_views_exposed_form_alter(&$form, &$form_state, $form_id) {
if (isset($form['sort_by'])) {
// Combine sort drop-downs into one.
$form['sorting'] = array(
'#type' => 'select',
'#id' => 'sort',
'#title' => $form['sort_by']['#title'],
);
foreach ($form['sort_by']['#options'] as $sort_by_key => $sort_by_title) {
foreach ($form['sort_order']['#options'] as $sort_order_key => $sort_order_title) {
$form['sorting']['#options'][$sort_by_key . '|' . $sort_order_key] = $sort_by_title . ' ' . $sort_order_title;
}
}
// Get default value for combined sort.
$sort_by_keys = array_keys($form['sort_by']['#options']);
$form['sorting']['#default_value'] = $sort_by_keys[0] . '|' . $form['sort_order']['#default_value'];
}
// Explode combined sort field into two values that are appropriate for views.
if (isset($form_state['input']['sorting'])) {
$sorting = explode('|', $form_state['input']['sorting']);
$form_state['input']['sort_by'] = $sorting[0];
$form_state['input']['sort_order'] = $sorting[1];
}
}
/**
* Default preprocess function for all filter forms.
*/
function MODULE_preprocess_views_exposed_form(&$vars) {
$form = &$vars['form'];
// Render new created sort field.
if (isset($form['sorting'])) {
$form['sorting']['#printed'] = FALSE;
$vars['sorting'] = drupal_render($form['sorting']);
// Need to rebuild the submit button.
$form['submit']['#printed'] = FALSE;
$vars['button'] = drupal_render_children($form);
}
}
Sau đó, bạn cần sao chép tệp "lượt xem / chủ đề / lượt xem-lộ-form.tpl.php" vào thư mục chủ đề của bạn và thay thế các tiện ích $ sort_by và $ sort_order bằng cách sắp xếp $ mới
Tìm thấy:
<?php if (!empty($sort_by)): ?>
<div class="views-exposed-widget views-widget-sort-by">
<?php print $sort_by; ?>
</div>
<div class="views-exposed-widget views-widget-sort-order">
<?php print $sort_order; ?>
</div>
<?php endif; ?>
Thay thế bằng:
<?php if (!empty($sorting)): ?>
<div class="views-exposed-widget views-widget-sort-by">
<?php print $sorting; ?>
</div>
<?php endif; ?>