New release of 5.x-1.7 improves in theme, also great to be compatible with CCK contemplate.

Compared with previous versions, 'Next' and 'Previous' , instead of node titles, are used for navigation. So, is it possible to give an option to select node title or next/pre?

Thanks again for this great module.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

eaton’s picture

I'm taking a look at providing customizable output options for the module -- ie, a field into which you can paste your own HTML for output. The reason the 'default' pager style was simplified was speed: using this option, it's not necessary to do a full node load on both the previous and next nodes.

BradM’s picture

Just wondering if anyone can quickly explain a temporary solution? I'd like the previous and next node titles to show up, rather than the default "previous" and "next" text.

I checked out the readme.txt file but I am completely lost. I created a function phptemplate_theme_custom_pager($nav_array, $node, $pager) and placed it within my template.php file, in order to customize. It mentions somewhere to use node_load(), but the only examples I could find were like this: $node = node_load($nid) -- however I can't see how that can be placed within this modified function anywhere.

Great module btw!!!

wayland76’s picture

Closed the duplicaate node linked below, which had some useful discussion.

http://drupal.org/node/185980

Michelle’s picture

Untested, but should work...

  $next_node = node_load($nav_array['next']);
  $links['custom_pager_next'] = array(
    'title' => $next_node->title,
    'href' => !empty($nav_array['next']) ? 'node/'. $nav_array['next'] : NULL,
  );

Michelle

lomz’s picture

Where do I place this code?

BradM’s picture

I've finally managed to get this to work. However, I had to modify custom_pagers.module directly; I couldn't get the code to work just by putting it in the theme's template.php file.

So, if you're feeling brave, edit your custom_pagers.module file, and replace the entire function theme_custom_pager with the following:

function theme_custom_pager($nav_array, $node, $pager) {
  drupal_add_css(drupal_get_path('module', 'custom_pagers') .'/custom_pagers.css');
  
  if (is_numeric($nav_array['prev'])) {
      $prev = node_load($nav_array['prev']);
    }
    if (is_numeric($nav_array['next'])) {
      $next = node_load($nav_array['next']);
  }
  
  $links = array();
    $links['custom_pager_prev'] = array(
      'title' => t('‹ ') . str_trim($prev->title),
      'href' => !empty($nav_array['prev']) ? 'node/'. $nav_array['prev'] : NULL,
    );
    $links['custom_pager_index'] = array(
      'title' => ($nav_array['current_index'] + 1) .' of '. count($nav_array['full_list']),
    );
    $links['custom_pager_next'] = array(
      'title' => str_trim($next->title) . t(' ›'),
      'href' => !empty($nav_array['next']) ? 'node/'. $nav_array['next'] : NULL,
  );
   
  return theme('links', $links, array('class' => "custom-pager custom-pager-$pager->pid custom-pager-$node->type"));
}

Important! Then add this function after it:

// Trim a string to specified length and append an end character (default = ...)
   function str_trim($str, $lim = 42, $chr = '...')
  {
       // If length of string is less than $lim, return string
       if (strlen($str = html_entity_decode($str)) <= $lim) return $str;
  
       // Else, cut string down to size
       return htmlentities(substr($str, 0, $lim - 3)).$chr;
  }

I suggest trying this on test site first -- I copied this from my file and removed some extra comments and minor modifications but the code should work as shown.

Brad

xaryss’s picture

I am still not having any luck with this either. Brad, your example did not seem to work for me.

Any other suggestions or instructions I can use?

BradM’s picture

Sorry, off of the top of my head, I don't. The code works at my site. When you said it didn't work for you, was there any change at all when you added this code? Since you're modifying the module file directly, you might also want to make sure the same function does not appear in your template.php file. Other than that, I'm not much of a coder so I can't think of what else to try.

asak’s picture

I tried using the code from theme_sample - but getting odd behavier:

Title pagers are not displayed when on the last node in the count.

I can see the pagers on nodes with "1 of 3" and "2 of 3" but not on "3 of 3" ... ?

Thoughts?

mattcasey’s picture

To replace 'previous' and next' with the node titles, create a custom-pager.tpl.php file in your theme folder:

<?php

/**
 * @file
 * custom-pager.tpl.php
 *
 * Theme implementation to display a custom pager.
 *
 * Default variables:
 * - $previous: A formatted <A> link to the previous item.
 * - $next: A formatted <A> link to the next item.
 * - $key: Formatted text describing the item's position in the list.
 * - $position: A textual flag indicating how the pager is being displayed.
 *   Possible values include: 'top', 'bottom', and 'block'.
 *
 * Other variables:
 * - $nav_array: An array containing the raw node IDs and position data of the
 *   current item in the list.
 * - $node: The current node object.
 * - $pager: The pager object itself.
 *
 * @see custom_pagers_preprocess_custom_pager()
 */
?>
<ul class="custom-pager custom-pager-<?php print $position; ?>">
<?php
  $next_node = node_load($nav_array['prev']);
  $title = $next_node->title;
  $href = !empty($nav_array['prev']) ? 'node/'. $nav_array['prev'] : NULL;
?>
<li class="previous"><?php print l($title, $href); ?></li>
<li class="key"><?php print $key; ?></li>
<?php
  $next_node = node_load($nav_array['next']);
  $title = $next_node->title;
  $href = !empty($nav_array['next']) ? 'node/'. $nav_array['next'] : NULL;
?>
<li class="next"><?php print l($title, $href); ?></li>
</ul>

13rac1’s picture

Status: Active » Closed (fixed)

Closing this three year old issue... ;)

areikiera’s picture

Version: 5.x-1.7 » 7.x-1.x-dev
Category: feature » support
Status: Closed (fixed) » Active

I think this is very helpful code, and I've edited it a little bit because I was receiving a non-object error on the first and last nodes. I think this may need to be updated a bit (for D7) and would really appreciate any feedback!

<?php
/**
 * @file
 * custom-pager.tpl.php
 *
 * Theme implementation to display a custom pager.
 *
 * Default variables:
 * - $previous: A formatted <A> link to the previous item.
 * - $next: A formatted <A> link to the next item.
 * - $key: Formatted text describing the item's position in the list.
 * - $position: A textual flag indicating how the pager is being displayed.
 *   Possible values include: 'top', 'bottom', and 'block'.
 *
 * Other variables:
 * - $nav_array: An array containing the raw node IDs and position data of the
 *   current item in the list.
 * - $node: The current node object.
 * - $pager: The pager object itself.
 *
 * @see custom_pagers_preprocess_custom_pager()
 */
?>
<ul class="custom-pager custom-pager-<?php print $position; ?>">
<?php
  $next_node = node_load($nav_array['prev']);
  if (!empty ($next_node)) {
	  $title = $next_node->title;
	  $href = !empty($nav_array['prev']) ? 'node/'. $nav_array['prev'] : NULL;
?>
  <li class="previous">&laquo; <?php print l($title, $href); ?></li>
<?php
  }
  $next_node = node_load($nav_array['next']);
  if (!empty ($nav_array['next'])) {
	  $title = $next_node->title;
	  $href = !empty($nav_array['next']) ? 'node/'. $nav_array['next'] : NULL;
?>
  <li class="next"><?php print l($title, $href); ?> &raquo;</li>
<?php
  }
?>
</ul>

Thanks!

gratefulsk’s picture

Works great! Thanks areikiera

scalas89 made their first commit to this issue’s fork.