Custom Pagers Code Snippet
Eingetragen von kloewer@drupal.org (79)
am 16.12.2009 - 03:05 Uhr in
am 16.12.2009 - 03:05 Uhr in
...
Kp, irgendwie ist das Modul Custom Pagers (http://drupal.org/project/custom_pagers) ja echt simpel zu bedienen, aber ich such mir jedes mal wieder einen Wolf wie ich den Pager denn nun in meinem angepassten Template node-CONTENTTYPE.tpl.php einbette.
Stell ich mich irgendwie an, bin ich da der einzige? Egal, wie dem auch sei, hier mal der Code:
<?php
print $node->content['custom_pager_top']['#children'];
?>
Vielleicht hat ja wer Lust noch weitere Schnipsel dazuzuschreiben, damit funktioniert es jedenfalls auch super...
###
Hier gibt's auch noch ne Anleitung: http://www.drupalcenter.de/handbuch/6250
- Anmelden oder Registrieren um Kommentare zu schreiben
Da custom_pagers einen Block
am 17.12.2009 - 15:26 Uhr
Da custom_pagers einen Block zurück liefert kannst du diesen auch direkt per module_invoke in die Seite einbinden..
Die Ausgabe im Inhaltstyp müsste dann wie folgt angepasst werden:
<?php
$pager = module_invoke('custom_pagers', 'block', 'view', 1);
print $pager['content'];
?>
Sauberer wäre es natürlich die "Sachen" über eine PreProcess Funktion in der template.php "laufen zu lassen" !
http://www.twitter.com/_steffenr
Drupal-Initiative e.V.
Basic Setup
am 26.04.2010 - 01:53 Uhr
Hier eine einfache Beschreibung zur Nutzung des Custom Pagers Modules:
http://drupal.org/node/371358
Anschließend füge ich immer folgenden Code ein:
<?php
print $node->content['custom_pager_top']['#children'];
?>
Nur 10 Einträge
am 26.04.2010 - 01:54 Uhr
Leider zeigt das Custom Pagers Modul in der 6.x-1.10-beta1 nur 10 Einträge an.
Abhilfe schafft:
http://drupal.org/node/276984#comment-1074872
custom_pagers.module UPDATE
am 26.04.2010 - 01:56 Uhr
Hier noch mal der Code der geänderten custom_pagers.module
<?php
// $Id: custom_pagers.module,v 1.6 2008/06/17 21:20:32 eaton Exp $
/**
* Implementation of hook_menu().
*/
function custom_pagers_menu() {
$items = array();
$access = user_access('administer custom pagers');
$items['admin/build/custom_pagers'] = array(
'title' => 'Custom pagers',
'description' => 'Add custom pagers for content types.',
'page callback' => 'custom_pagers_page',
'access arguments' => array('administer custom pagers'),
'file' => 'custom_pagers.admin.inc',
);
$items['admin/build/custom_pagers/add'] = array(
'path' => 'admin/build/custom_pagers/add',
'title' => 'Add custom pager',
'type' => MENU_CALLBACK,
'page callback' => 'drupal_get_form',
'page arguments' => array('custom_pagers_form'),
'access arguments' => array('administer custom pagers'),
'file' => 'custom_pagers.admin.inc',
);
$items['admin/build/custom_pagers/edit'] = array(
'title' => 'Edit custom pager',
'type' => MENU_CALLBACK,
'page callback' => 'drupal_get_form',
'page arguments' => array('custom_pagers_form', 4),
'access arguments' => array('administer custom pagers'),
'file' => 'custom_pagers.admin.inc',
);
return $items;
}
function custom_pagers_perm() {
return array('administer custom pagers', 'use php in custom pagers');
}
function custom_pagers_theme() {
return array(
'custom_pager' => array(
'arguments' => array(
'nav_array' => NULL,
'node' => NULL,
'pager' => NULL,
'position' => 'bottom',
),
'template' => 'custom-pager',
),
);
}
function custom_pagers_nodeapi(&$node, $op, $teaser, $page) {
switch ($op) {
case 'view':
// We want to make sure we don't try to output when print.module is active.
// It's a bit of special casing but it doesn't do much harm.
if ($teaser == false && empty($node->printing)) {
$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) {
switch ($pager->position) {
case 'top':
$node->content['custom_pager_top'][$pager->pid] = array('#value' => theme('custom_pager', $nav_array, $node, $pager, 'top'));
break;
case 'bottom':
$node->content['custom_pager_bottom'][$pager->pid] = array('#value' => theme('custom_pager', $nav_array, $node, $pager, 'bottom'));
break;
case 'both':
$node->content['custom_pager_top'][$pager->pid] = array('#value' => theme('custom_pager', $nav_array, $node, $pager, 'top'));
$node->content['custom_pager_bottom'][$pager->pid] = array('#value' => theme('custom_pager', $nav_array, $node, $pager, 'bottom'));
break;
}
}
}
}
if (isset($node->content['custom_pager_top'])) {
$node->content['custom_pager_top']['#weight'] = -100;
}
if (isset($node->content['custom_pager_bottom'])) {
$node->content['custom_pager_bottom']['#weight'] = 100;
}
}
break;
case 'update':
case 'insert':
case 'delete':
// If a user makes any changes to a node, we want to make sure that
// their pager cache is cleared. It's ugly, but it should prevent some
// of the nastier cache-went-stale issues.
unset($_SESSION['custom_pagers']);
break;
}
}
/**
* Implementation of hook_block().
*
* Generates a block with a pager for the current node.
*/
function custom_pagers_block($op = 'list', $delta = 0) {
if ($op == 'list') {
$pagers = _custom_pagers_load_all_pagers();
foreach ($pagers as $pager) {
if ($pager->position == 'block') {
$blocks[$pager->pid]['info'] = $pager->title;
}
}
return $blocks;
}
else if ($op == 'view' && arg(0) == 'node' && $node = menu_get_object()) {
$pagers = _custom_pagers_load_all_pagers();
if ($pager = $pagers[$delta]) {
if ($pager->position == 'block' && _custom_pagers_visibility($pager, $node)) {
$nav_array = custom_pager_build_nav($pager, $node);
if ($nav_array['current_index'] != -1) {
if (module_exists('token')) {
$block['subject'] = token_replace($pager->title, 'node', $node);
}
else {
$block['subject'] = $pager->title;
}
$block['content'] = theme('custom_pager', $nav_array, $node, $pager, 'block');
return $block;
}
}
}
}
}
function _custom_pagers_load_pager($pid) {
$sql = 'SELECT * FROM {custom_pager} WHERE pid = %d';
$result = db_query($sql, $pid);
$pager = db_fetch_object($result);
return $pager;
}
function _custom_pagers_load_all_pagers($refresh = FALSE) {
static $pagers;
if ($refresh || !isset($pagers)) {
$sql = 'SELECT * FROM {custom_pager}';
$result = db_query($sql);
$pagers = array();
while($pager = db_fetch_object($result)) {
$pagers[$pager->pid] = $pager;
}
}
return $pagers;
}
function _custom_pagers_save_pager($pager = NULL) {
if (isset($pager->pid)) {
drupal_write_record('custom_pager', $pager, array('pid'));
}
else {
drupal_write_record('custom_pager', $pager);
}
cache_clear_all('custom_pagers_', 'cache', TRUE);
}
function _custom_pagers_delete_pager($pid) {
$sql = 'DELETE FROM {custom_pager} WHERE pid = %d';
db_query($sql, $pid);
}
function _custom_pagers_visibility($pager, $node) {
$visible = FALSE;
if (!empty($pager->visibility_php)) {
// Use PHP code to generate the list.
ob_start();
$result = eval(trim($pager->visibility_php));
$visible = ($result == TRUE);
ob_end_clean();
} elseif (!empty($pager->node_type)) {
$visible = (strpos($pager->node_type, $node->type) !== FALSE);
}
return $visible;
}
function custom_pager_build_nav($pager, $node) {
static $pager_cache;
$list = array();
// First we check the static function cache for this pager.
// If it's already been built for this page-load, we'll use it.
if (isset($pager_cache[$pager->pid])) {
$list = explode(',', $pager_cache[$pager->pid]);
}
// If it doesn't give us a list, and the pager is set to cache its
// data, we'll try to load from the current user's session. We do it
// that way rather than via cache_set() because of the potential for
// node_access violations. Each user's node list *could* be different.
if (empty($list) && $pager->cache_list) {
if ($cache = $_SESSION['custom_pagers'][$pager->pid]) {
// We should probably set the pager cache lifetime to a configurable
// value. If any nodes drop through the cracks, users won't see the
// pager when they visit them. Five minutes should keep the pager from
// thrashing. In the future, we'll want to develop a better strategy
// for this.
if ($cache['timestamp'] < (time() - 300)) {
unset($_SESSION['custom_pagers'][$pager->pid]);
}
else {
$list = explode(',', $_SESSION['custom_pagers'][$pager->pid]['data']);
}
}
}
// If $list is still empty, neither caching strategy produced a list.
// Let's build it from scratch!
if (empty($list)) {
// If the pager uses PHP, execute the PHP and run with the list.
// Otherwise, use a view to get a list of node ids.
if (!empty($pager->list_php)) {
// Use PHP code to generate the list.
ob_start();
$result = eval(trim($pager->list_php));
if (is_array($result)) {
$list = $result;
}
ob_end_clean();
}
elseif (module_exists('views') && $view = views_get_view($pager->view)) {
// Get arguments for the view.
if (isset($pager->args)) {
$args = explode("\n", $pager->args);
if (module_exists('token')) {
$args = token_replace($args, 'node', $node);
}
$view->set_arguments($args);
}
// Make sure the query is not cached
$view->is_cacheable = FALSE;
$view->pager['items_per_page'] = 0;
$view->execute_display();
if (isset($view->result)) {
foreach($view->result as $result) {
$list[] = $result->nid;
}
}
}
if ($pager->reverse_list) {
$list = array_reverse($list);
}
}
// If we get to this point, we want to cache what we've made.
if ($pager->cache_list) {
$_SESSION['custom_pagers'][$pager->pid]['data'] = implode(',', $list);
$_SESSION['custom_pagers'][$pager->pid]['timestamp'] = time();
}
$pager_cache[$pager->pid] = $list;
return pager_entries_by_val($node->nid, $list);
}
// Helper functions to pull proper entries from a list of nids.
function pager_entries_by_val($value, $list) {
$list = array_values($list);
foreach ($list as $k => $v) {
if ($v == $value) {
$key = $k;
}
}
if (!isset($key)) {
$key = -1;
}
return pager_entries_by_key($key, $list);
}
function pager_entries_by_key($key, $list, $increment = 1) {
$list = array_values($list);
$nav = array(
'first' => $list[0],
'prev' => $list[max($key - $increment, 0)],
'next' => $list[min($key + $increment, (count($list) - 1))],
'last' => $list[count($list) - 1],
'full_list' => $list
);
foreach($nav as $k => $v) {
if ($nav[$k] == $list[$key]) {
$nav[$k] = NULL;
}
}
$nav['current_index'] = $key;
return $nav;
}
function custom_pagers_preprocess_custom_pager(&$vars) {
drupal_add_css(drupal_get_path('module', 'custom_pagers') .'/custom_pagers.css');
$node = $vars['node'];
$pager = $vars['pager'];
$nav = $vars['nav_array'];
$vars['first'] = !empty($nav['first']) ? l("<span class='first'><img src='http://spiffyd.com/img/nav/first.png'/></span>",'node/'. $nav['first'], array("html"=>true)) : '';
$vars['previous'] = !empty($nav['prev']) ? l("<span class='previous'><span class='previous-text'>prev post</span></span>",'node/'. $nav['prev'], array("html"=>true)) : '';
$vars['key'] = t('@count of @count_total', array('@count' => ($nav['current_index'] + 1), '@count_total' => count($nav['full_list'])));
$vars['last'] = !empty($nav['last']) ? l("<span class='last'><img src='http://spiffyd.com/img/nav/last.png'/></span>",'node/'. $nav['last'], array("html"=>true)) : '';
$vars['next'] = !empty($nav['next']) ? l("<span class='next'><span class='next-text'>next post</span></span>",'node/'. $nav['next'], array("html"=>true)) : '';
/*
$vars['previous'] = !empty($nav['prev']) ? l(t('« previous'), 'node/'. $nav['prev']) : '';
$vars['key'] = t('@count of @count_total', array('@count' => ($nav['current_index'] + 1), '@count_total' => count($nav['full_list'])));
$vars['next'] = !empty($nav['next']) ? l(t('next »'), 'node/'. $nav['next']) : '';
*/
$vars['suggestions'][] = "custom-pager-{$vars['position']}";
$vars['suggestions'][] = "custom-pager-$node->type";
$vars['suggestions'][] = "custom-pager-$node->type-{$vars['position']}";
$vars['suggestions'][] = "custom-pager-$pager->pid";
$vars['suggestions'][] = "custom-pager-$pager->pid-{$vars['position']}";
$vars['template_files'] = $vars['suggestions'];
}
ich habe den custom pager
am 16.05.2010 - 18:09 Uhr
ich habe den custom pager auch installiert auf meinem lokalen System.
Dort läufts auch.
Wenn ich diesen auf meine Homepage online stelle, mit den gleichen Einstellungen sehe ich den Pager nicht mehr.
An was kann das liegen?
Danke.