NewsFeaturesDownloadsDevelopmentSupportAbout Us
Plugin categorybrowser

Plugin categorybrowser

From LifeType Wiki


Name: categorybrowser

Latest version: 20070302

Download link: http://prdownloads.sourceforge.net/lifetype/1.2_categorybrowser.zip?download

License: GPL

Author: Jon Daley

Live Demo: My Blog

[edit] Description

Given a post and category, this plugin can return the next and previous post within that category. Additionally, given a category, this plugin can return the first and last post in the category.

[edit] Configuration

You can use:

  1. $categorybrowser->getFirstArticle($categoryId, $blogId) to get the first article in the category.
  2. $categorybrowser->getPrevArticle($post, $categoryId, $blogId) to get the article in this category just prior to the given post.
  3. $categorybrowser->getNextArticle($post, $categoryId, $blogId) to get the article in this category just after the given post.
  4. $categorybrowser->getLastArticle($categoryId, $blogId) to get the last article in the category.


Example:

Add the following code to any template file where you want it to show:
Category

 {foreach name=categories from=$post->getCategories()
          item=postCategory}
   {assign var=categoryName value=$postCategory->getName()}
   {assign var="blogId" value=$blog->getId()}
   {assign var="categoryId" value=$postCategory->getId()}
   {assign var="postInCategoryFirst"
         value=$categorybrowser->getFirstArticle($categoryId, $blogId)}
   {assign var="postInCategoryPrev"
         value=$categorybrowser->getPrevArticle($post, $categoryId, $blogId)}
   {assign var="postInCategoryNext"
         value=$categorybrowser->getNextArticle($post, $categoryId, $blogId)}
   {assign var="postInCategoryLast"
         value=$categorybrowser->getLastArticle($categoryId, $blogId)}
     <a href="{$url->categoryLink($postCategory)}">{$categoryName}</a>:
     <a href="{$url->postPermalink($postInCategoryFirst)}">first</a>
     <a href="{$url->postPermalink($postInCategoryPrev)}">previous</a>
     <a href="{$url->postPermalink($postInCategoryNext)}">next</a>
     <a href="{$url->postPermalink($postInCategoryLast)}">newest</a>
 {/foreach}

The code I actually use on my blog
Fancier code, better spacing, removes redundant links, and adds paranoid checks to avoid errors (shouldn't ever happen, but that's what paranoia is all about)
Category

 {foreach name=categories from=$post->getCategories()
          item=postCategory}
   {assign var=categoryName value=$postCategory->getName()}
   {assign var="blogId" value=$blog->getId()}
   {assign var="categoryId" value=$postCategory->getId()}
   {assign var="postInCategoryFirst"
         value=$categorybrowser->getFirstArticle($categoryId, $blogId)}
   {assign var="postInCategoryPrev"
         value=$categorybrowser->getPrevArticle($post, $categoryId, $blogId)}
   {assign var="postInCategoryNext"
         value=$categorybrowser->getNextArticle($post, $categoryId, $blogId)}
   {assign var="postInCategoryLast"
         value=$categorybrowser->getLastArticle($categoryId, $blogId)}
   <a href="{$url->categoryLink($postCategory)}">{$categoryName}</a>:
   
     {if $postInCategoryFirst &&
         ($postInCategoryFirst->getId() != $post->getId())}
       [<a
       href="{$url->postPermalink($postInCategoryFirst)}">first</a>]
     {/if}
     {if $postInCategoryPrev &&
         ($postInCategoryPrev->getId() != $postInCategoryFirst->getId())}
       [<a
       href="{$url->postPermalink($postInCategoryPrev)}">previous</a>]
     {/if}
     {if $postInCategoryNext &&
         ($postInCategoryNext->getId() != $postInCategoryLast->getId())}
       [<a
       href="{$url->postPermalink($postInCategoryNext)}">next</a>]
     {/if}
     {if $postInCategoryLast &&
         ($postInCategoryLast->getId() != $post->getId())}
       [<a
       href="{$url->postPermalink($postInCategoryLast)}">newest</a>]
     {/if}
   
 {/foreach}