LifeType 1.0/Plugins/stickyposts

LifeType 1.0/Plugins/stickyposts

出自LifeType 中文文件計畫

(修訂版本間差異)
跳轉到: 導航, 搜尋

在2005年11月27日 (日) 17:00所做的修訂版本


名稱: 文章置頂及公告

版本: 1.0

下載連結http://prdownloads.sourceforge.net/plog/stickyposts.zip?download

程式授權: GPL

作者: lss

用途

提供網誌做文章置頂及用文章做為網站公告。

設定

後台管理部份:

  1. 首先請建立兩個文章分類存放公告及置頂文章。
  2. 你可以在 個人網誌設定 >> 置頂及公告文章設定 進行各項設定。
  3. 預設的置頂文章數目公告文章數目是 5 篇文章,你可以修改成你要顯示的數目。
  4. 在選單中選擇存放置頂文章及公告文章的分類。

在樣版檔案裡,你可以使用:

  1. $stickyposts->isEnabled() 檢查 plugin 是否已經啟用。
  2. $stickyposts->getArticles( 'sticky' ) 傳回置頂文章的 article 陣列,最多傳回所設定的置頂文章數目。
  3. $stickyposts->getArticles( 'announce' ) 傳回公告文章的 article 陣列,最多傳回所設定的公告文章數目。
  4. $stickyposts->getArticles( 12 ) 傳回指定文章分類 ID 的所有文章 article 陣列。本例中的 12 為文章分類 ID。
  5. $stickyposts->getCategory( 'sticky' ) 傳回用於置頂文章的 category 物件,可用來做成更多置頂文章超連結。
  6. $stickyposts->getCategory( 'announce' ) 傳回用於公告文章的 category 物件,可用來做成更多公告文章超連結。
  7. $stickyposts->getCategory( 12 ) 傳回指定文章分類 ID 的 category 物件。

其中 'sticky' 和 'announce' 是 plugin 的保留字。

樣版檔範例:

這是一個非常簡單的樣版檔範例,用來展示 Sticky Posts Plugin 的用法。它是以 'blueish' 樣版為例做修改。

{include file="$blogtemplate/header.template"}
<div id="content">
{if $stickyposts->isEnabled()}
  <h2>Sticky Posts</h2>
  {assign var=stickys value=$stickyposts->getArticles('sticky')}
  {foreach from=$stickys item=post}
      <h2 class="title"><a href="{$url->postPermalink($post)}">{$post->getTopic()}</a></h2>
  {/foreach}
  {assign var=stickyCategory value=$stickyposts->getCategory('sticky')}
  <h4><a href="{$url->categoryLink($stickyCategory)}">more sticky posts</a></h4>
  
  <h2>Announce Posts</h2>
  {assign var=stickys value=$stickyposts->getArticles('announce')}
  {foreach from=$stickys item=post}
      <h2 class="title"><a href="{$url->postPermalink($post)}">{$post->getTopic()}</a></h2>
  {/foreach}
  {assign var=announceCategory value=$stickyposts->getCategory('announce')}
  <h4><a href="{$url->categoryLink($announceCategory)}">more announce posts</a></h4>
{/if}  
  {foreach from=$posts item=post}
    {include file="$blogtemplate/post.template"}
  {/foreach}
</div>
{include file="$blogtemplate/panel.template"}
{include file="$blogtemplate/footer.template"}

如果只要在首頁顯示置頂文章與最新消息,只要在相關的樣版程式碼:(第 3 行的{if $stickyposts->isEnabled()}到倒數第 6 行的{/if})前後加上 $showAll 變數的判斷即可。

{if empty($showAll)}
{if $stickyposts->isEnabled()}
.....
{/if}
{/if}

注意事項

上面的樣版檔範例是一個很差的範例,請樣版高手製作又好又漂亮的樣版,並請隨手將這個範例換掉。

2005-05-18 更新:上面的範例倒數第 6 行少了一個{/if},已更正。

2005-05-18 更新:加入只在首頁顯示置頂與最新消息的方法。

其他範例

這裡有一個使用stickyposts實作「在單篇彙整頁面中顯示同類別上下篇連結」的範例