A friend of mine ran into this issue a while ago: Node listings like on the frontpage or for categories are not really themeable. The nodes themselves are, of course, but the list is not.
This makes it - at least - very hard, if you want for exampel surround all sticky nodes with a single div for design reasons. Or if want your node list to be a definition list, rather than a set of divs. Or...
Additionally, since a theme function is missing, there is a lot of duplicated code around Drupal modules that usually looks like this:
$output = '';
while ($node = db_fetch_object($result)) {
$output .= node_view(node_load($node->nid), 1);
}
Grep for "node_view(node_load(" on the sources to find all the occurences.
I therefore suggest to add a function theme_node_listing to node.module (the name "theme_node_list" is already occupied) to contain this code:
function theme_node_listing($result) {
$output = '';
while ($node = db_fetch_object($result)) {
$output .= node_view(node_load($node->nid), 1);
}
return $output;
}
Note that the function takes a database result as argument.
The code mentioned above then can be replaced by
$output = theme('node_listing', $result);
Having centralized node listing formatting this way, the original problem of surrounding sticky nodes with a div can be solved by simply overloading the theme function in the theme engine of choice.
Comments
Comment #1
stevenpatzFeatures go in cvs.
Comment #2
gerd riesselmann commentedSince nothing happened here and 5.0 is already in Beta, I'm increasing priority of this.
I stumbled upon this missing feature on two other projects in the meantime. For example it is rather hard and ugly to place Adsense code within a node listing, so implementing the #1 web business model is unnecessarily complex.
I see no real reason to not provide this theme function and it also does not cause any compatibility issues. I therefore guess this request just has been overlooked. That's why I bring it up again, too.
Comment #3
dodorama commentedinteresting
Comment #4
RobRoy commentedI suggest using the Views module http://drupal.org/project/views. Once you create a 'view' or a listing of nodes, you will be able to theme every aspect of it in your template.php and with your node-whatever.tpl.php files. Search around drupal.org for information on views.
Comment #5
gerd riesselmann commentedHmm, I'm not satisfied. While the answer itself might be a reasonable hot fix, if this was a bug report, it isn't for the feature request this is.
Views module is rather clumsy, at least for my taste. Introducing the theme function I suggested on the other hand makes live a lot easier, and is really simple to implement - and understand.
Comment #6
gerd riesselmann commentedComment #7
dodorama commentedCan you make a patch out of it?
Maybe this would increase core-developer attention on this issue.
Comment #8
willmoy commentedI think now that everything's becoming views, the world has moved on?