home


Top
   Info
   Internet News
   Poll Archive
   Contact
   Site Map
Smarty Textblock pagination

Very simple plugin to paginate block of text with smarty. it will split text into chunks and will create small navigation menu.

copy this to your smarty plugins folder block.paginate.php

 <?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     block.paginate.php
 * Type:     block
 * Name:     paginate
 * Purpose:  paginate content
 * -------------------------------------------------------------
 */
function smarty_block_paginate($params, $content, &$this)
{
  if (is_null($content)) {
   return;
  }
  extract($params);
  if (!isset($page_name)) $page_name='page';
  if (!isset($split_name)) $split_name='<NEWPAGE>';
  if (isset($get_params[$page_name])) $current_page=$get_params[$page_name];

  $Pages = explode( "$split_name", $content );
  $TotalPages = sizeof( $Pages );

  if ($TotalPages== 1)
  {
   return $content;
  }
  elseif($TotalPages>1)
  {
   if (!$current_page) $current_page = 1;

   foreach ($get_params as $key => $value)
   {
    if ($key != "$page_name")
    {
     $link_params.="$key=$value&";
    }
   }
   $linkage="<br>";
   $i=1;
   while ($i <= $TotalPages)
   {
    $linkage.=($i==$current_page)?"[<b>$i</b>]":"<a href='$script?".$link_params.$page_name."=".$i."'>$i</a>";
    $i++;

   }

   return $Pages[$current_page-1].$linkage;
  }
  else
  {
   return;
  }

}
?>

go to page 2 for usage


[1]2
spacer