开发者

Drupal 7 Views 3: Displaying the number of displayed nodes? Example: (Showing 3842 of 5382 results)

How could we display the number of displayed nodes in a View? Like: "Showing 3842 of 5382 results"

Then if all nodes in the View are displayed at once, (often initially), it might say: "Showing all 5382 results"

The开发者_C百科n if no nodes in the View are displayed from the filter, it might say: "Found no results"

Is this very hard? I think it would be a very useful addition and would appreciate any help with this.


I'm sure this could be done more succinctly. But I wanted to make it clear what I was doing. So here it is. Basically you can use this in the header or footer of your view.

<?php
$view = views_get_current_view();
$c = $view->total_rows;
$cp = $view->get_current_page();
$pp = $view->get_items_per_page();
$si = ($cp * $pp) + 1;
$ei = $si + ($pp - 1);

if($c > 0) {
  if($pp < $c) {
    if($ei > $c) {
      print "Showing $si to $c of $c results";
    } else {
      print "Showing $si to $ei of $c results";
    }
  } else {
    print "Showing all $c results";
  }
} else {
  print "Found no results";
}
?>


1) go to edit view

2) add field

3) Global: View result counter

4) Profit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜