简体   繁体   中英

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"

Then 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM