4

I have several views on my Drupal site. I also have a page that links to those views. I would like to see the number of items (e.g. the number of pages) that are listed in each view:

  • link to foobar view [5 items]
  • link to other view [0 items]

Is there an easy way to do this. I suppose I will need embedded PHP for this, but I would like to avoid huge SQL statements embedded in my linking page.

migrated from webmasters.stackexchange.com Jun 21 '11 at 11:54

This question came from our site for pro webmasters.

3

You can get the amount of results in a view using their API calls.

<?php
$views = view::load("viewname");
$view->set_display('default'); //optional, could be default, OR the name of a specific display
$views->execute();
echo count($views->result);
?>

I tested this on views 3 (the current version). For further reading, check out http://groups.drupal.org/node/10129. It's written for views 2, but still relevant.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.