Hey,
My goal is to display only 5 results in a taxonomy list page.
I think this function dictates it:
from taxonomy.module
/**
* Accepts the result of a pager_query() call, such as that performed by
* taxonomy_select_nodes(), and formats each node along with a pager.
*/
function taxonomy_render_nodes($result) {
$output = '';
$has_rows = FALSE;
while ($node = db_fetch_object($result)) {
$output .= node_view(node_load($node->nid), 1);
$has_rows = TRUE;
}
if ($has_rows) {
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10), 0);
}
else {
$output .= '<p>'. t('There are currently no posts in this category.') .'</p>';
}
return $output;
}
Now I am tring to create a hook for it and run it in one of my own modules:
/**
* Accepts the result of a pager_query() call, such as that performed by
* taxonomy_select_nodes(), and formats each node along with a pager.
*/
function best_render_nodes($result) {
$output = '';
$has_rows = FALSE;
if(!(arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2)))){
$limit = 5;
}
$count = 0;
while ($node = db_fetch_object($result)) {
$output .= node_view(node_load($node->nid), 1);
$has_rows = TRUE;
$count++;
if($limit && $count == $limit){
break;
}
}
if ($has_rows) {
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10), 0);
}
else {
$output .= '<p>'. t('There are currently no posts in this category.') .'</p>';
}
return $output;
}
But drupal doesn't go through there. I tried clearing the cache. I tried putting it in template.php and renamed the function to function phptemplate_render_nodes($result)
I have used hooks before to customize core functions without touching them. But it is not working here.
(Also if there is some super easy solution, like changing a setting in the admin pages, then whoops! let me know if there is haha).
I am pretty curious why the hook here is not working though, I feel I am missing some fundamental understandings here.
Appreciate it,
Eric
Comments
render_nodes is not a hook
The hook is not working, because _render_nodes is not a hook, i.e. it is never called by module_invoke_all in the taxonomy module. Apart from that, _render_nodes is not the one you want to be overriding: as the documentation you copied states, it merely accepts the results from a pager_query() call. So what you could do is write your own pager_query() and pipe the result to taxonomy_render_nodes.
Okay I see that. But where
Okay I see that.
But where in drupal's core is it really calling for 10 listed nodes to display on the taxonomy page? (I.e., it is calling node.tpl.php 10 times).
I would like to just reduce that number to 5 times---and keep track of which iteration we are on as well.
Once I know that, then I'll know how to make drupal trigger my own function best_show_five_nodes (I hope).
-Eric
EDIT:
Oh, wait.. is it this function?
How do I make sure the taxonomy pages call this with a limit of 5? (at least I assume that is the limit holding the display to 10 nodes..)
Bump...
Bump...
Have you considered...
Taxonomy List
NancyDru
NancyDru