function paging_build_names in Paging 7
Returns a rendered list of page links.
Parameters
$nid: Node ID to render page links for.
Return value
An array of page names linked to the pages of the post.
1 call to paging_build_names()
- paging_block_view in ./
paging.module - Implements hook_block_view().
File
- ./
paging.module, line 467 - Allows a node to be broken into multiple pages via a tag.
Code
function paging_build_names($nid = NULL) {
global $pager_page_array;
global $language;
// Load node ID form URL, if none was supplied.
$nid = $nid ? $nid : arg(1);
// Fetch a structured array containing page names.
$names = paging_fetch_names($nid);
// Load the node object to counting total number of expected pages.
$node = node_load($nid);
// Invoke 'load' operation in hook_nodeapi() implementation to calculate the actual number of pages in the node body.
paging_node_load(array(
$node,
), array(
$node->type,
));
// Comparing and mapping the number of pages in $names and $node->page_count.
$fake = array_fill(0, ($node->paging[$language->language]['page_count'] - 1 < 1 ? 1 : $node->paging[$language->language]['page_count'] - 1) + 1, '');
$length = count($fake) > count($names) ? count($fake) : count($names);
$merged = array();
for ($i = 0; $i < $length; ++$i) {
$merged[$i] = array_key_exists($i, $names) ? $names[$i] : '';
}
// Fill the empty names with node title and page number.
$names = _paging_populate_empty_names($merged, $node->title);
$rendered_links = array();
// Element value to distinguish between multiple pagers on one page.
$element = 1;
// Convert the names into links.
foreach ($names as $key => $name) {
$page_new = pager_load_array($key, $element, $pager_page_array);
$rendered_links[] = theme('pager_link', array(
'text' => $name,
'page_new' => $page_new,
'element' => $element,
));
}
return theme('item_list', array(
'items' => $rendered_links,
));
}