Custom pager theming examples
Last modified: March 1, 2009 - 21:03
This is a page of example code and templates for custom pagers. Please add your own!
Using these examples
Theming a custom pager can involve making several changes to your theme:
- creating a function phptemplate_preprocess_custom_pager in your theme's template.php file
- creating template files in your theme folder, eg. custom-pager.tpl.php
First and Last links
In template.php:
function phptemplate_preprocess_custom_pager(&$vars) {
// if we're at the end, the nav_array item for this (eg first) is NULL;
// no need to compare it to current index.
$vars['first'] = empty($vars['nav_array']['first']) ? '' : l('first', 'node/' . $vars['nav_array']['first']);
$vars['last'] = empty($vars['nav_array']['last']) ? '' : l('last', 'node/' . $vars['nav_array']['last']);
}Add a custom-pager.tpl.php:
<ul class="custom-pager custom-pager-<?php print $position; ?>">
<li class="first"><?php print $first; ?></li>
<li class="previous"><?php print $previous; ?></li>
<li class="key"><?php print $key; ?></li>
<li class="next"><?php print $next; ?></li>
<li class="last"><?php print $last; ?></li>
</ul>
Using image thumbs from image module
This goes in template.php:
function prevnext_nav($nid) {$result = db_query("SELECT i.image_size, f.filepath FROM {image} i INNER JOIN {files} f ON i.fid = f.fid WHERE i.nid = %d", $nid);
$images = array();
while ($file = db_fetch_object($result)) {
$images[$file->image_size] = file_create_path($file->filepath);
}
return '<img src="/'. $images['thumbnail'].'">';
}
And here's my custom-pager.tpl.php:
<ul class="custom-pager custom-pager-<?php print $position; ?>"><div id="icon-pager">
<li class="previous">
<?php
print '<div class="prev-icon" >'. l(prevnext_nav($nav_array['prev']), 'node/'. $nav_array['prev'], $options = array('html' => TRUE)) .'</div>';
print $previous; ?>
</li>
<li class="key"><?php print $key; ?></li>
<li class="next"><?php
print '<div class="next-icon" >'. l(prevnext_nav($nav_array['next']), 'node/'. $nav_array['next'], $options = array('html' => TRUE)) .'</div>';
print $next; ?></li>
</ul>
</div>
Very cool. How can you do
Very cool. How can you do this with a CCK ImageField? Any ideas?
thanks
I'm using this code to
I'm using this code to replace the 'previous' and 'next' links with images. The 'next' image it's working but I just can't replace the 'previous' link with the image. Any advice on this?
function mytheme_preprocess_custom_pager(&$vars) {// if we're at the end, the nav_array item for this (eg first) is NULL;
// no need to compare it to current index.
$path = drupal_get_path('theme', 'terniumgrey');
$vars['prev'] = empty($vars['nav_array']['prev']) ? '' : l("<img src=\"". base_path() . $path ."/images/bullet_back.gif\" />", 'node/' . $vars['nav_array']['prev'], array('html' => TRUE));
$vars['next'] = empty($vars['nav_array']['next']) ? '' : l("<img src=\"". base_path() . $path ."/images/bullet.gif\" />", 'node/' . $vars['nav_array']['next'], array('html' => TRUE));
}
Luis
$vars['prev'] should be
$vars['prev']should be$vars['previous']Check
<?php print $previous; ?>, you're printing the $previous variable, not $prevHope this helps.
Best regards,
Karel
I wanted my pager in a block,
I wanted my pager in a block, so I just added the following code to a block. I hope to tidy and possibly add a patch to add a block to the module.
<?php
if(arg(0) == 'node' && is_numeric(arg(1))){
$node = node_load(arg(1));
$pagers = _custom_pagers_load_all_pagers();
foreach ($pagers as $pager) {
if ($pager->position != 'block' && _custom_pagers_visibility($pager, $node)) {
$nav_array = custom_pager_build_nav($pager, $node);
if ($nav_array['current_index'] != -1) {
print( theme('custom_pager', $nav_array, $node, $pager, 'top'));
}
}
}
}
?>
----------------------------------------------------------------
Millwood Online http://www.millwoodonline.co.uk
Blog to it http://blog.to.it
Spun Designs http://www.spundesigns.net
IB Community Theme http://communitytheme.ibo.org