将公开的过滤器视为链接列表而不是选择

发布于 2024-08-19 21:01:24 字数 679 浏览 5 评论 0原文

使用 Drupal 6、Views 2 和公开的过滤器,我试图确定将选择列表转换为链接列表的最佳方法,每个链接都有一个匹配节点的数量。例如,而不是我默认得到的,作为选择列表:

<select name="state" class="form-select" id="edit-state" >
<option value="All" selected="selected">&lt;Any&gt;</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
...
</select>

我想得到类似的东西,

<p>Restrict results by state:<br />
<a href="...">Alabama (15)</a><br />
<a href="...">Alaska (7)</a><br />
...
</p>

每个链接都在括号中显示计数,并以与选择第一个代码块中的选项之一相同的方式向下钻取。

您能否提供有关如何解决此问题的任何指示?谢谢。

Using Drupal 6, Views 2 with exposed filters, I'm trying to determine the best way to convert the select list to a list of links, each with a count of matching nodes. For instance instead of what I get by default, as a select list:

<select name="state" class="form-select" id="edit-state" >
<option value="All" selected="selected"><Any></option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
...
</select>

I'd like to get something like

<p>Restrict results by state:<br />
<a href="...">Alabama (15)</a><br />
<a href="...">Alaska (7)</a><br />
...
</p>

With each link showing the count in parentheses and drilling down in the same way that selecting one of the options in the first code block would.

Could you provide any pointers on how to approach this? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

洒一地阳光 2024-08-26 21:01:24

您可能需要查看 Better Exposed Filters 模块以获取视图。 7.x 版本具有此功能,6.x 版本也有一个补丁,可以在以下位置找到:

http://drupal.org/node/1159232#comment-4710372

You may want to look at the Better Exposed Filters module for views. The 7.x version has this functionality and there is a patch for the 6.x version as well which can be found at:

http://drupal.org/node/1159232#comment-4710372

苍景流年 2024-08-26 21:01:24

Solr 很灵活,但也可以查看视图中的摘要选项。您可以在视图附带的“存档列表”视图的参数部分中看到这样的示例。

drupal.org 上还有其他一些多面浏览模块,但我没有任何个人经验。

Solr is slick, but also check out the summary option in Views. You can see an example of this in the arguments section of the "Archive list" view that comes with Views.

There are some other faceted browsing modules on drupal.org as well but I haven't got any personal experience with them.

思念绕指尖 2024-08-26 21:01:24

你所追求的并不是视图应该做的事情。这可能是可行的,但实施起来会很慢而且很困难。

相反,您应该看看 Acquia 为 Apache Solr 制作的模块。它进行分面搜索,这正是您真正想要做的。如果您的情况足够简单,您可能不需要如此花哨的东西。但这只是时间问题。性能将成为一个大问题,因为您需要对每个状态进行查询才能获取计数。

What you are after is not something views was meant to do. It probably would be possible to do, but it will be slow and hard to implement.

Instead you should take a look at the module Acquia has made for Apache Solr. It does faceted search, which is what you really are trying to make. If your case is simple enough you might not need something so fancy. But it's just a matter of time before you do. Performance will become a big issue since you would need to do a query per state to get the counts.

攒一口袋星星 2024-08-26 21:01:24

检查此问题http://drupal.org/node/891974
该代码用于计算每页的帖子数量,但也可以轻松地应用于其他过滤器。

Check this issue http://drupal.org/node/891974.
The code is for the number of posts per page, but can easily be done to other filters too.

小糖芽 2024-08-26 21:01:24
<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>
<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文