Error message

Notice: Undefined offset: 1 in counter_get_browser() (line 70 of /home/weldon/www/sites/all/modules/counter/counter.lib.inc).

Drupal Views Table Row Number (descending order) / Drupal Views表格序號(降冪排序)

Categories : 

在Drupal中,Views是用來呈現資料最常使用的一個模組

In Drupal, Views is a common module used to display information.

使用表格來呈現網站中的資訊,也是大家非常常使用的一種方式

Use table to present datas in the website is a common way as well.

在表格中,要如何顯示欄位的序號(降冪排列),則是這篇文章要跟大家方想的部分了

This article shares how to show the row numbers of the table in descending order.

 

表格序號的降冪排列,主要是用在網站作品與設計作品的頁面上

I want to display table row in Website Works page and Design Works page.

在Views本身的功能中,表頭(Header)與表尾(Footer)有提供Views Summery的功能 (Table1)

In Views, it provided a "Views Summery" function to display total number of items in Header or Footer.

另外在Views的欄位中有Global: View result counter的欄位可以增加,但這個欄位會顯示升冪的序號

Besides, you may also add a filed called "Global: View result counter" in the views field area. But this field will display ascending order number.

要顯示降冪的序號,需要配合Views PHP這個模組

In order to display descending order number, Views PHP is used to achieve the function.

Step1. Install Views PHP 安裝Views PHP


安裝Views PHP 模組

Install Views PHP module (as the way you install other modules)

URL: https://www.drupal.org/project/views_php

Step2. Add fields in Views 在Views中新增欄位


field1

新增一個Global: PHP欄位

Add a "Global: PHP" field

在Output code的地方,新增下列語法

Add following code in the "Output code" area

勾選不要顯示這個欄位

Mark up "Exclude from display"

<?php
$view = views_get_current_view();
$view->execute();
$count = count( $view->result );
print $count;
?>

field2

欄位新增一個Global: View result counter欄位

Add a "Global: View result counter" field

在起始值的地方輸入0

Enter "0" in "Starting value"

勾選不要顯示這個欄位

Mark up "Exclude from display"

field3

欄位新增一個Global: Math expression欄位

Add a "Global: Math expression" field

在Expression的地方輸入[php]-[counter]

Enter "[php]-[counter]" in "Expression" area

 

完成啦!

Done!

 

成果

Result

 

這次我的方法啦,跟有需要的朋友分享,當然如果你有更好的處裡方式,也歡迎你告訴我!

Share this method with needed friend!

Read more about: