[WordPress] 外掛分享: CSV to SortTable

首頁外掛目錄 › CSV to SortTable
WordPress 外掛 CSV to SortTable 的封面圖片
⚠ 此外掛已下架 — 不再更新維護,建議勿安裝。
100+
安裝啟用
★★★★
4.9/5 分(11 則評價)
4634 天前
最後更新
問題解決
WordPress 3.2.1+ v4.2 上架:2011-11-07

內容簡介

CSV to SortTable 插件非常適合想要在 WordPress 網站上展示試算表資訊的使用者。此插件可用於顯示產品目錄、庫存清單、排行榜或任何存儲在 CSV 檔案中的內容。

使用方式

使用以下簡碼在任何頁面或文章中插入可排序的表格:

[csv src=http://example.com/myfile.csv]

結果將是一個漂亮、語意正確的 HTML 表格,其內容為您的檔案。

選用功能

此插件自動為您執行一些動作,全部可禁用:

新增了一些 CSS 以使表格顯示得更好看。
將圖片檔案 URL 轉換為可點擊的圖片連結。
將某些檔案 URL 轉換為可點擊的檔案類型圖示 (.doc、.pdf、.ppt、.xls、.zip)。

使用 disable 簡碼屬性就可以停用任何其中一些功能:

[csv src=http://example.com/myfile.csv disable=css]
[csv src=http://example.com/myfile.csv disable=icons,images]
[csv src=http://example.com/myfile.csv disable=all]

第一個範例僅停用插件 CSS;第二個範例會停用檔案類型圖示和影像連結;而第三個範例會停用所有選用功能。使用逗號分隔的清單 (不含空格) 停用任何組合。

表格 ID

想要為表格指定唯一的 ID 嗎?使用 id 簡碼屬性:

[csv src=http://example.com/myfile.csv id=my_data_table]

上面的範例會給 <table> 元素新增一個 id 屬性為 my_data_table。

分組類別

假設您有一個具有三個欄位的表格:物品、描述和類型。您希望所有相同類型的表格列具有相同的類別,這樣就可以使用 CSS 以不同的顏色加以凸顯,或使用 JavaScript 一次性修改它們。

可藉由將欄位編號指定為 group 簡碼屬性完成此操作:

[csv src=http://example.com/myfile.csv group=3]

結果會根據第三個欄位的值,指定每個表格列的特殊類別。

排序選項

預設情況下,表格資料以字母順序排序。如果您希望對欄位進行數字或日期排序,或在某些欄位上禁用排序,則可以使用以下簡碼屬性:

[csv src=http://example.com/myfile.csv number=2]
[csv src=http://example.com/myfile.csv date=3]
[csv src=http://example.com/myfile.csv unsortable=4,5,6]

值可以是單個欄位編號,也可以是逗號分隔的多個欄位編號清單 (不含空格!)。

相對檔案路徑

如果 src 值是相對路徑 (以斜線開頭),則插件將參照 WP-Admin > 設定 > 一般 中定義的「網站位址 (URL)」:

[csv src=/mydata/data.csv]

上面的範例會參照 http://example.com/mydata/data.csv。

資料陣列篩選器

您可能希望在匯入 CSV 資料後,但在呈現 HTML 表格之前,對這些資料進行操作。為此,請使用此篩選器:

csv_to_sorttable_data_array

以下是如何使用資料陣列篩選器的一些程式碼範例:

移除第一列(函數)
新增標題列(函數)

外掛標籤

開發者團隊

⬇ 下載最新版 (v4.2) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「CSV to SortTable」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

CSV to SortTable is great for anyone who wants to display information from a spreadsheet on a WordPress website. This plugin can be used to display product catalogs, inventory lists, leaderboards or anything else that can be stored in a CSV file.
How To Use
Insert a sortable table into any page or post using this shortcode:
[csv src=http://example.com/myfile.csv]

The result will be a beautiful, semantically-correct HTML table populated with the contents of your file.
Optional Features
This plugin automatically does a few things for you, all of which can be disabled:

Adds some CSS to make the table look nice.
Converts image file URLs into clickable image links.
Converts certain file URLs into clickable file-type icons (.doc, .pdf, .ppt, .xls, .zip).

To disable any of these features, use the disable shortcode attribute:
[csv src=http://example.com/myfile.csv disable=css]
[csv src=http://example.com/myfile.csv disable=icons,images]
[csv src=http://example.com/myfile.csv disable=all]

The first example would disable only the plugin CSS; the second would disable both the file-type icons and image links; and the third would disable all optional features. Disable any combination using a comma-separated list (no spaces!).
Table ID
Want to give your table a unique ID? Use the id shortcode attribute:
[csv src=http://example.com/myfile.csv id=my_data_table]

The above example would give the

element an id attribute of my_data_table.
Group Classes
Let’s say you have a table with three columns: Item, Description and Type. You want all table rows of the same Type to have the same class, so you can highlight them in different colors using CSS or modify them all at once with JavaScript.
This can be done by assigning a column number to the group shortcode attribute:
[csv src=http://example.com/myfile.csv group=3]

The result would be a special class assigned to each table row based on the value of the third column.
Sorting Options
By default, table data is sorted alphabetically. If you want to sort columns numerically or as dates, or disable sorting on certain columns, use the following shortcode attributes:
[csv src=http://example.com/myfile.csv number=2]
[csv src=http://example.com/myfile.csv date=3]
[csv src=http://example.com/myfile.csv unsortable=4,5,6]

The values can be a single column number, or multiple column numbers in a comma-separated list (no spaces!).
Relative File Paths
If the src value is a relative path (beginning with a forward slash), the plugin will refer to the “Site address (URL)” defined in WP-Admin > Settings > General:
[csv src=/mydata/data.csv]

The above example would refer to http://example.com/mydata/data.csv.
Data Array Filter
You may want to manipulate the CSV data after it is imported, but before the HTML table is rendered. To do so, use this filter:
csv_to_sorttable_data_array

Here are some code examples of how to use the data array filter:

Remove First Row (Function)
Add a Header Row (Function)
Add a Header Row (Plugin)

Credits
This plugin utilizes some excellent open source scripts, functions and images whose creators deserve to be recognized.

Stuart Langridge wrote sorttable.js, the JavaScript that inspired this plugin and makes it possible to sort tables by clicking on the column headers.
V.Krishn wrote a handy PHP function that enables users of PHP < 5.3 to utilize the str_getcsv() function that powers this plugin. Blake Knight created the beautiful file type icons used in this plugin and made them free for all.

延伸相關外掛

文章
Filter
Apply Filters
Mastodon