Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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

This question came from our site for pro webmasters.

up vote 3 down vote accepted

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

$views = view::load("viewname");
$view->set_display('default'); //optional, could be default, OR the name of a specific display
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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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