Views

How to get views result count programmatically - Drupal 7

The current project I'm working on has a lot of customization of Drupal Commerce and display of views. One of the customization I've done is while displaying views result, show total of two views results in one view i.e. there are two views viewA and viewB shown on page, which shares the output and so we need to show the sum of total results in viewA and viewB will be displayed in viewA header.

Here's how I've achieved this with only few lines of code:

Tweak exposed form in Views in Drupal

Views module provides the ability to site admin to allow users to select the filters and dynamically refine the results based on selection made. This can be achieved using exposed filters in views. By default the exposed form looks like normal form i.e. fields to select filter, Apply button to get refined results, etc.

Using views UI, we can tweak exposed form and do following things, without writing a single line of code:

Drupal - Change label of exposed filter form button in views

Views one of the great module available in Drupal. Views can be used to show various types of dynamic data and can also be used to allow users to filter results based on his criteria. To allow users to filter results based on his criteria we normally use views "exposed filter" option in every filter we add in view (screenshot 1.0).

How to alter views exposed filter allowed value list

Just came across a situation, where wanted to alter the allowed values in views exposed filter depending on users who are viewing them.

View allows site admin to expose its filter value to user, so they can apply different filters while viewing views output. But what if you need to show the allowed list depending on users.

Programmatically render views in Drupal 7

Views can be used to display content as a page, block, etc. You can directly access URL to show page view content, you can add views block in any region if it is to be shown on sidebar first, sidebar second, content top, content bottom. What if the content of views block needs to be shown inside the content of page. So here is sample code to render the views programmatically in Drupal 7 in just one line: