How to create a view in Drupal
In this post we will discuss how to create view to display the listing for the content types in drupal sites. In Drupal, you can create dynamic pages from administrative menu > content management > content > Add Option. So, if you are creating some dynamic content E.g. pages where you should like to list the records for a particular set of data fields, then to fulfill this requirement you need to create a View which will display you the listing of the contents of any content types.
Here are some simple steps to create view for any content type. This example has been created using Drupal 5.10.
Step 1 :Basic View Setup
Download the view module (http://drupalmodules.com/module/views) and install the module. Once you enable the view module to can create view for all content types. From administrative menu/site building/views click on add option. Once, you click on the add option you will get a form as shown in figure below.
Basic information is the general information about the view which you will create.
Step 2 : Creating the View Display
You can display your created view in a page,block and both. Its up to to you how would you like to get the output. For your help we are creating both the page and block. Please check the snapshots given below.
(a) Creating a page for the view.
Firstly, you have to check the provide page view option and give the URL of the view page. Use pager is the option for the pagination. If you don’t want pagination just unchecked the checkbox.
b) Creating a Block for the view.
Check the provide block option to create a block for the view. Nodes per block indicated how many nodes you want to show in you block.
Step 3 : Selecting the fields
Fields – Select the fields which you want to display for this content types. In our example, we are showing the node title and node body. You need to choose the field from the drop down and click on the add Field button. The selected field will display above as shown in figure.
Step 4 :View Arguments
Arguments – If you want to display a particular node then you need to configure this argument section otherwise leave it blank. If you want to display a particular node then you select the argument from the drop down which you want to pass for the node and click add argument. The selected argument will show above as shown in figure.
Now, you need to set the wildcard value. Wildcard is the value which you pass from the URL. This will automatically fetch the value and show the corresponding node content.
For example, if you want to show node whose node ID is 11 then select node ID as the argument and set wildcard to %1.
%1 represent 11, the first argument you pass from the URL i.e., http://localhost/drupaldemo/?q=admin/build/views/page_entry/11
%2 represent 22, the second argument you pass from the URL i.e., http://localhost/drupaldemo/?q=admin/build/views/page_entry/11/22
Step 5 :Creating Filters for the View
Filters – From this filter section you can filter the nodes which you want to show into your view page. In our example, we are filtering through node type and this is the simple and general way to filter. Select the Node: type from the dropdown and a click on the add filter button. Then select the page as the value of the node type.
Actually, in our example we are filtering the page type from all nodes through this filter option.
Step 6 : Set Your Sort Criteria
Sort Criteria – Select the field from the dropdown to sort. In our example, we are sorting as node ID i.e., latest node entry will show at the top of the listing. See the snapshot given below.
Step 7 : Confirm the changes and preview the ‘View’
Finally, click on the save button to save all the provided information. Once, the view is save you can access the page by the URL you have provided. For our example, URL name is viewPage and to see the listing of the page nodes the url is http://sitename/?q=viewPage.
You will get the full url of your view page from Administrative menu > site building > views > Listing page. You can also edit and delete this view from the section.