Building a Drupal site from scratch - part 4 - Creating views

| Drupal Development | 0 seen

<p>Let's move on with our tourism companies website tutorial.</p><p>In part 1 we created a custom content type - Tours, now it's time to make a few views which will contain data from node related to content type - tours.</p><p>Before creating views - we must download a few modules, to get them work:</p><ul><li><a href="https://drupal.org/project/views">Download Views</a></li><li><a href="https://drupal.org/project/ctools">Download Ctools</a></li><li>Extract both to sites/all/modules</li><li>Enable Views, Views UI modules</li></ul><div>A bried explanation from creators of Drupal views:</div><div><ul><li>You like the default front page view, but you find you want to sort it differently.</li><li>You like the default taxonomy/term view, but you find you want to sort it differently; for example, alphabetically.</li><li>You use /tracker, but you want to restrict it to posts of a certain type.</li><li>You like the idea of the 'article' module, but it doesn't display articles the way you like.</li><li>You want a way to display a block with the 5 most recent posts of some particular type.</li><li>You want to provide 'unread forum posts'.</li><li>You want a monthly archive similar to the typical Movable Type/Wordpress archives that displays a link to the in the form of "Month, YYYY (X)" where X is the number of posts that month, and displays them in a block. The links lead to a simple list of posts for that month.</li><li>Views can do a lot more than that, but those are some of the obvious uses of Views.</li></ul><div>&nbsp;</div><div>If you followed tutorial <a href="http://reinisfischer.com/building-drupal-site-scratch-part-3-better-adm… 3 - for better site administration</a>, then you have admin menu installed. After enabling Views module, we can find path to views under Structure menu, if not, you must go to /structure/views</div></div><div>&nbsp;<img src="http://reinisfischer.com/sites/default/files/addviews.JPG&quot; alt="" width="583" height="164"></div><div>&nbsp;</div><div>&nbsp;</div><div>&nbsp;</div><div>We gonna add new view: Tours, with page (path) and custom block:</div><div>&nbsp;</div><div><img src="http://reinisfischer.com/sites/default/files/toursview.png&quot; alt="" width="1052" height="347"></div><div>&nbsp;</div><div>&nbsp;</div><div>As you can see from picture above we are filtering content type Tour. Click Continue and edit.</div><div>&nbsp;</div><div>&nbsp;</div><div><img src="http://reinisfischer.com/sites/default/files/featuredtours.png&quot; alt="" width="1190" height="560"></div><div>&nbsp;</div><div>&nbsp;</div><div>&nbsp;</div><div>From picture above you can see, that I have added a block, and renamed it Featured tours - it will be the block container, which will showcase Featured tours, based on whether content is marked sticky, or not. To add such behaviour, we must add a filter - sticky:</div><div>&nbsp;</div><div>&nbsp;</div><div><img src="http://reinisfischer.com/sites/default/files/stickyfilter.JPG&quot; alt="" width="925" height="433"></div><div>&nbsp;</div><div>&nbsp;</div><div>Pay attention that I have applied this filter just for this, and not all displays.</div><div>&nbsp;</div><div>For now save the view.&nbsp;</div><div>&nbsp;</div><div>Now by accessing path /tours, we can see all tours we have entered.&nbsp;</div><div>&nbsp;</div><div><img src="http://reinisfischer.com/sites/default/files/tourpath.JPG&quot; alt="" width="1056" height="487"></div><div>&nbsp;</div><div>In next part's I'll show how to theme views, where to put Featured tours block we just created, how to add menu items, and how to setup a custom frontpage.</div>