Jump to content


Snippet Advice


  • You cannot reply to this topic
No replies to this topic

#1 suzkaw

    Etomite Forum Newbie

  • Member
  • 1 posts

Posted 17 May 2006 - 10:01 PM

I am using Etomite for a documentation/article site and I want to be able to page the articles. So I have built a snippet to this but it requires changing the template tag [*content*] to [[PagedContent]]. This works fine for me but I was just wondering if anyone can think of a better/easier way to format the text without having to edit this template tag or if it even matters.

Here is the code I currently have working without SEO urls and you have to manually enter [PAGEBREAK] into the article text where you want it broken.

#  PagedContent-- Etomite 0.6.1
#  Author: Eric Barnes
#  Date: 2006-05-17
#  Purpose: Returns a portion of the content and pages the rest.
#  Usage: [[PagedContent]]

	//process the querystring//
	$queryString_search = "";
	if (!empty($_SERVER['QUERY_STRING'])) 
	{
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) 
  {
 	 $param=htmlspecialchars($param);
 	 if (stristr($param, "page") == false) 
 	 {
     array_push($newParams, $param);
 	 }
  }
  if (count($newParams) != 0) 
  {
 	 $queryString_search = "?" . implode("&", $newParams);
  }
	}
	//I don't like this and I am sure there is a better way.
	$currentPage=$_SERVER['PHP_SELF'] . $queryString_search;
	
	if(!isset($id)) 
	{
  if(isset($_GET['page']) && $_GET['page'] <> 0)
  {
 	 $page=(int)$_GET['page'];
  }
  else 
  {
 	 $page=0;
  }
  
  $id = $etomite->documentIdentifier;
  $fields = "content";
  $doc = $etomite->getDocument($id, $fields);
  if($doc)
  {
 	 $content=spliti('\[PAGEBREAK]',$doc['content']);
 	 $output=$content[$page];
 	 
 	 $output.='<div class="page"> &raquo; Page &nbsp;';
	
 	 $array_count=count($content);
 	 for($y=0; $y<$array_count; $y++) 
 	 {
    $nextpage=$y+1;
    if($page==$y)
    {
   	 $output.='<strong>'.$nextpage.'</strong>&nbsp;';
    }
    else
    {
   	 $output.='<a href='.$currentPage.'&page='.$y.'>'.$nextpage.'</a>&nbsp;';
    }
 	 }
 	 return $output;
  }
  else
  {
 	 return "";
  }
	}
	else 
	{
  return "";
	}

Edited by suzkaw, 17 May 2006 - 10:02 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users