Nodes per Page setting
| Project: | Insert View |
| Version: | 5.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
I setup my Drupal homepage so that it displays two views using this syntax: [view:name_of_view].
For both of these views I set them up as Page views. Everything worked fine with the exception that the 'Nodes per Page' setting did not seem to work. I set it at two and it would display greater than two.
My solution was to go into the views.module code and add a few lines to theme_views_view_nodes so that the 'Nodes per Page' setting is enforced. You can take a look at my setup at http://groups.ischool.berkeley.edu/samuelsonclinic. Note that what you are viewing is with my code in place. Did I do this wrong?
Here is my code. Lines with a JCD comment are mine.
/**
* Display the nodes of a view as plain nodes.
*/
function theme_views_view_nodes($view, $nodes, $type, $teasers = false, $links = true) {
// JCD added lines to this function so that it adheres to the Nodes per Page limit setting.
$count = $view->nodes_per_page; // JCD
foreach ($nodes as $n) {
if ($count) { // JCD
$node = node_load($n->nid);
$output .= node_view($node, $teasers, false, $links);
} // JCD
$count--; // JCD
}
return $output;
}

#1
Have you tried the panels module? It might fit your needs of showing several views together.
#2
My primary issue was not with showing more than one view on the same page -- that worked using [view:view_name] syntax within the node body. It was with the 'Nodes per Page' limit not working when I used the [view:view_name] to render a view.
Hopefully this makes sense. Also note that I solved my problem (as per the code I snippet in my original post). I guess I am wondering if the views module has a bug wherein it doesn't enforce the Nodes per Page limit properly when using the [views:view_name] syntax.
Thanks.
#3
This syntax:
[view:name_of_view]is the insert_view module. That module is responsible for figuring out the right nodes_per_page setting when calling views_build_view(). Views just does what the calling module says, there.#4
Ahh problem solved.
You can use [view:viewname=5=arg1,arg2,arg3]
Where 5 is the node display limit. Thanks.
#5
I wonder if there's a way to get the Pager portion to work as well.
#6
Same problem here. Is there no way to get the pager working with [view:view_name=5] for example?
#7
Just reopening this to note that pagination is turned off by design in the module. There may be a reason for this. I am guessing that it may introduce bugs during sorting or filtering.
The attached SVN patch (sorry no CVS utility at hand), will re-enable the default behavior of view defined pagination and nodes per page if unspecified. I've only used this using a teaser list, but I have not had problems.
Alan D.
#8
There is a recently released 5.x-1.0 release of Insert View and it provides a way for you to insert a paged view vs. a non-pager view. Selection of the proper Insert View tag ought to give the desired behavior.
Please see the 5.x-1.0 README.txt for more info and syntax.
mlsamuelson
#9
Automatically closed -- issue fixed for two weeks with no activity.