简体   繁体   English

在Drupal上添加排序到视图?

[英]Adding sorting to a view on Drupal?

I used to know how to do this, but I can't seem to get sorting to work on a view where filters are exposed in a block. 我曾经知道如何做到这一点,但我似乎无法对在块中暴露过滤器的视图进行排序。 I want to be able to filter by, for example, type, price etc, but then also have sorting options to sort by these items. 我希望能够通过例如类型,价格等进行过滤,但随后还有排序选项以按这些项目排序。

How do I get sorting to work like this? 如何让排序工作这样?

I used that code to override sorting in non-table views 我使用该代码覆盖非表视图中的排序

function views_tweak_views_query_alter(&$view, &$query) {
  if ($view->name == 'products'){
  if (arg(3) == 'pu') $query->orderby[0]='uc_products_sell_price ASC';
  if (arg(3) == 'pd') $query->orderby[0]='uc_products_sell_price DESC';
  if (arg(3) == 'nu') $query->orderby[0]='node_title ASC';
  if (arg(3) == 'nd') $query->orderby[0]='node_title DESC';

  } 
}

and placing into view template links with those urls 并放入视图模板链接与这些网址

AFAIK you can't expose sort criteria like you can with filters. AFAIK您不能像过滤器那样公开排序条件。

I looked a bit around a found this module . 我看了一下发现这个模块 The idea is to create several views each with a different sort criteria and link them together with tabs. 我们的想法是创建多个视图,每个视图使用不同的排序条件,并使用制表符将它们链接在一 It's a bit hackish and might not work with exposed filters. 它有点hackish,可能无法使用暴露的过滤器。 The module is still in beta release, and I haven't tested it, so can't say if it's any good. 该模块仍在测试版中,我还没有测试过,所以不能说它是否有用。

If you choose to use a table layout, you can sort by columns. 如果选择使用表格布局,则可以按列排序。 That functionality is built into views. 该功能内置于视图中。

Just in case you cannot find where to set this, look on the left side of the View (in Edit mode), under Basic Settings, select "Table". 如果您无法找到设置位置,请查看视图左侧(在编辑模式下),在基本设置下,选择“表格”。 The click the "settings" (looks like a little gear icon to the right of the "table" selection), and you'll see a list of all the display fields, where you can select which ones are sortable/not, and which is the default sort. 单击“设置”(看起来像“表格”选项右侧的一个小齿轮图标),您将看到所有显示字段的列表,您可以在其中选择哪些是可排序/不可以,哪些是默认排序。

Adding sorting to a view on Drupal less programm code in hooks. 在Drupal中添加排序,在钩子中减少程序代码。

You need to use arguments in display page. 您需要在显示页面中使用参数。

Use taxonomy menu for pages before.. Next: 在页面之前使用分类法菜单..下一个:

  1. Create one display page in view with path (for example): some_path/%/by_totalcount 在路径中创建一个显示页面(例如):some_path /%/ by_totalcount
    1.1. 1.1。 Make sort criteria for this display by totalcount 按totalcount为此显示制作排序条件
  2. Make another one dislplay page in this view with path (for example): some_path/%/by_date 在此视图中使用path(例如)创建另一个显示页面:some_path /%/ by_date
    2.1. 2.1。 Make sort criteria for this display by date 按日期为此显示制作排序条件
  3. Create new block with code: 使用代码创建新块:

<?php $url= urldecode($_SERVER['REQUEST_URI']); switch($url) { case '1': $class = 'top'; $title_h2 = 'top'; break; case '/taxonomy/term/6 3 ': $class = 'travel'; $title_h2 = 'travel'; break; ................. } global $base_url; $url_rating = $base_url.'/'.arg(0).'/'.arg(1).'/'.arg(2).'/rating'; $url_created = $base_url.'/'.arg(0).'/'.arg(1).'/'.arg(2); ?> <div class="<?php print $class; ?>"> <div class="title"> <h2> <?php print $title_h2; ?></h2> <p>Sort node: <span class="sort_type"><a href="<?php echo $url_rating; ?>">by rate</a></span> | <span class="sort_type"> <a href="<?php echo $url_created; ?>">by date</a></span></p> </div> </div> <p>&nbsp;</p>

VOILA VOILA


Sorry for my english.. it isn't my native language )) 对不起我的英文..这不是我的母语))


声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM