article custom (zh-tw)
From Textbook
Contents |
類型
article_custom 為 單一標籤,提供文章在排序、列表與顯示上更多樣化的選擇
Textpattern 會以一篇或多篇文章取代此標籤。
不同於 <txp:article /> 的是,article_custom 將永遠傳回文章列表,且該列表並無 上下相承 的關係。這代表當 <txp:article /> 只能顯示目前版區下的內容時,article_custom 卻可列出全部版區下的所有內容,除非設置了 section 屬性(請見下面)。
註:在 article_custom 之下,txp:next 與 txp:prev 標籤會無法運作。
相關資訊:自訂 txp:recent_articles (這裡有一份關於 <txp:article /> 與 <txp:article_custom /> 的相異處之 對照文件)
語法
article_custom 標籤的語法結構如下...
<txp:article_custom />
屬性
此標籤接受下列的屬性,這些屬性可以視需要個別或搭配使用 (區分大小寫):
-
id="integer" - 任何一個已發表文章之 id#。
-
form="form name" - 使用特定的模型。預設為
default. 請見 模型。 -
section="section name" - 只列出某版區下的內容。
-
category="category name" - 只列出某分類下的內容。
sort="sort option"- (詳情如下) [4.0.4]
-
sortby="sort by" - 依某規則排序。接受的值為:
ID(依文章id#)、
AuthorID (依作者)、
LastMod (依最後修改時間)、
LastModID (依最後修改作者)、
Posted (依發表時間)、
Title (依標題)、
Category1(依分類一)、
Category2(依分類二)、
comments_count (依迴響篇數)、
Status (依狀態)、
Section (依版區)、
Keywords (依關鍵字)、
Image (依附加圖片 id#)、
url_title
和 custom_1 至 custom_10。註:可以使用多重排列依據,以 , 分隔。 你也可以依 先日期再分類排序 (details SQL calls that sortby accepts)。 不適用於 4.0.4.
-
sortdir="sort direction" - 文章的排序方向。 接受的值為:
asc(順序排列),ordesc(逆序排列). 不適用於 4.0.4.
-
limit="integer" - 列出的文章篇數。 預設為
10。 -
offset="integer" - 第一篇列出的文章之偏移值。 預設為
0。 -
excerpted="excerpt value" - 只列出摘要。接受的值為:
y(列出摘要) 或n(不列出摘要). -
author="author's name" - 只列出特定作者的文章。
-
month="yyyy-mm" - 只列出特定月份的文章。
-
keywords="keywords" - 只列出含有特定關鍵字的文章。 以 , 分隔。
-
customfieldname="value" - 只列出特定自訂欄位為某值的文章。將 "customfieldname" 以自訂欄位名稱取代。
-
time="time" - 只列出特定時間所發表的文章。接受的值為:
past(過去),future(未來),或any( 包含past(過去) 與future(未來) ). 預設為past. -
status="status" - 依狀態列出文章。 接受的值為:
draft(草稿),hidden(非公開),pending(待審),live(已發表),sticky(置頂). -
allowoverride="integer" - 當設置為
0時,即代表不允許覆蓋預設文章列表模型(does not effect individual articles)。接受的值為1或0。
listform 屬性已不存在於 article_custom (只適用於 article),請以 條件式標籤 取代。
屬性解說
- sort: 這個屬性值的使用方式就像 SQL 查詢子句
order by一樣;以 txp_link 資料表為例,它的任何一個欄位名都可指定 。要指定排序方式,後面可跟著 SQL sort order 排序關鍵字asc(順序、由上至下、第一個到最後一個) 或desc(逆序、由下至上、最後一個到第一個)。某些標籤的排序依據可使用url,linkname desc,description asc,date asc,rand()等。
範例
範例 1: 顯示發表於2004年10月的文章列表
<txp:article_custom form="month_list" sortby="Section" sortdir="asc" month="2004-10" />
範例 2: 顯示含有關鍵字 One 的文章列表
<txp:article_custom sortby="Posted" sortdir="desc" keywords="One" />
範例 3: 依特定作者顯示標題連結清單
<txp:article_custom form="author_list" author="Parkling" />
author_list article 模型可以這樣設置
<p><txp:permlink><txp:title /></txp:permlink></p>
範例 4: 顯示自訂欄位名"colour" 欄位值"red" 的文章列表
<txp:article colour="red" />




