Hello:

I'm using Drupal 4.6.2 and I have installed two modules - directory.module and pagination.module. Both are up and running beautifully, but I have a problem with combining the two. I'm trying to come up with pagination specifically for the directory page and unfortunately it's not working out. The pagination module works well on nodes but not the directory.

This is the code for the pagination module:

/**
 * filter to set up page numbers for multiple page articles,
 *    based on suggestions by Prometheus6 on http://drupal.org/node/23362#comment-40580
 * @file pagination.module 
 * @author Kitt Hodsden http://kitt.hodsden.com/
 * @license Creative Commons BY-NC-SA, http://creativecommons.org/licenses/by-nc-sa/2.0/
 */

/**
 * help hook
 */
function pagination_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t("Handles splitting long nodes into several pages, allowing for full node view also.");
  }
}

/**
 * settings hook
 */
function pagination_settings() {

	// set up the params via pageNo URL variable or URL directly
	$o  = form_textfield(t('Text before page links'), 'pagination_pre', variable_get('pagination_pre', 'Go to page: '), 30, 255, t('Text displayed before the pagination links'));
	$o .= form_textfield(t('Previous page'), 'pagination_prev', variable_get('pagination_prev', 'previous'), 30, 255, t('Previous page link text'));
	$o .= form_textfield(t('Next page'), 'pagination_next', variable_get('pagination_next', 'next'), 30, 255, t('Next page link text'));
	$o .= form_textfield(t('Single page text'), 'pagination_single', variable_get('pagination_single', 'single page'), 30, 255, t('Single page link text'));

	return $o;
}


/**
 * nodeapi hook
 */
function pagination_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {

  switch ($op) {

  case 'view':

	  if ($page === true) {
		  
		  // explode the body on the <!--pagebreak--> tag
		  $pages = explode('<!--pagebreak-->', $node->body);
		  
		  // if more than one page, generate the links on the bottom
		  if (count($pages) > 1) {
			  
			  // process only if the user doesn't want all the pages
			  $pageNo = $_GET['pageNo'];
			  
			  $totalPages = count($pages);
			  
			  // check we're not too far or too few
			  if (!isset($pageNo) || empty($pageNo)) {
				  $pageNo = 1;
			  }
			  
			  if ($pageNo > $totalPages) {
				  $pageNo = $totalPages;
			  }
			  
			  if ($pageNo != 'ALL') {
				  
				  $basepage = $_GET['q'];
				  
				  for($i = 1; $i <= $totalPages; $i++) {
					  if ($pageNo != $i) {
						  $links .= l($i, $basepage, array(), 'pageNo=' . $i) . ' ';
					  } else {
						  $links .= $i . ' ';
					  }
				  }
				  
				  $prev = (($pageNo - 1) < 1) ? 1 : ($pageNo - 1);
				  $next = (($pageNo + 1) > $totalPages) ? $totalPages : ($pageNo + 1);
				  
				  if ($pageNo > 1) {
					  $x = variable_get('pagination_prev', 'previous');
					  if ($x != '') {
						  $links = l($x, $basepage, array(), 'pageNo=' . $prev . ' ') . ' | ' . $links;
					  }
				  }
				  
				  if ($pageNo < $totalPages) {
					  $x = variable_get('pagination_next', 'next');
					  if ($x != '') {
						  $links .= ' | ' . l($x, $basepage, array(), 'pageNo=' . $next . ' ');
					  }
				  }
				  
				  $node->body = $pages[($pageNo - 1)] . '<p />' . variable_get('pagination_pre', 'Go to page:') . $links . ' | ' . l(variable_get('pagination_single', 'Single page'), $basepage, array(), 'pageNo=ALL' . ' ');
				  
			  } // end check for ALL param
			  
		  } // end check for > 1 page to display
		  
	  } // end check if we're on a page
	  
	  break;
	  
  } // end switch
} 

Can anyone help me make this work for the directory module? I would REALLY appreciate it. Thanks!

Comments

syren-1’s picture

No-one knows how to make this work for the directory module? Someone please help!!

syren-1’s picture

Really desperately needing help here!!