Drupal: .htaccess Access Deny
August 21, 2012 – 7:59 am | No Comment

In this article I will tell how to forbid access to certain resources for some clients. The instructions will include descriptions of different directives.

First let’s speak about Order directive of .htaccess file of Apache server.
Description: …

Read the full story »
CSS Templates

Contain reviews and news about CSS Templates.

Freebies

Contain freebies such as icons, graphics, headers and images for your websites.

Fun Stuff

Contains other fun stuff for entertainment or interesting site showcase.

How-To

Contain technical elaborations on some specific workarounds or common tweak.

Joomla Templates

Contains reviews and news about Joomla templates.

Home » Add-ons, How-To

How to Drupal: Views Module

Submitted by on February 15, 2010 – 12:24 pmOne Comment

Though Views module is not standard Drupal module, it is one of the basic modules. I install Views every time creating a website even if I’m not going to use it so far. I’m sure that first or last I will need Views!

In this article I would tell you about Views module and describe how you can work with it on the example of creating a block that would display the last articles added to your site.

The Views module provides a flexible method for Drupal site designers to control how lists and tables of content (nodes in Views 1, almost anything in Views 2) are presented. Traditionally, Drupal has hard-coded most of this, particularly in how taxonomy and tracker lists are formatted.

This tool is essentially a smart query builder that, given enough information, can build the proper query, execute it, and display the results. It has four modes, plus a special mode, and provides an impressive amount of functionality from these modes.

Among other things, Views can be used to generate reports, create summaries, and display collections of images and other content.

What the official documentation tells about Views?

You need Views if:

  • You like the default front page view, but you find you want to sort it differently.
  • You like the default taxonomy/term view, but you find you want to sort it differently; for example, alphabetically.
  • You use /tracker, but you want to restrict it to posts of a certain type.
  • You like the idea of the ‘article’ module, but it doesn’t display articles the way you like.
  • You want a way to display a block with the 5 most recent posts of some particular type.
  • You want to provide ‘unread forum posts’.
  • 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.

Views can do a lot more than that, but those are some of the obvious uses of Views.

So, if you wish to use Views for your Drupal web-site, download it and install. You can find the detailed instruction of how to install Drupal modules here: http://www.templatezine.com/2010/01/how-to-install-a-new-module-to-drupal-based-site/. Enable all components for this module.

Let’s proceed. Now we are going to create a block that would show the last 5 articles added to the website.

Navigate to the Administer > Site building > Views item of the admin menu:

clip_image001

And then click Add tab:

clip_image003

Fill in the details of our block:

clip_image005

Please make sure that you’ve selected Node for the View type.

You will then see the Latest News settings:

clip_image007

Add fields for your block with the latest articles.

Fields are only applicable to a view if either the page or block type is set to List or Table view. If using a purely teaser view, fields will be ignored. Fields tell Views exactly what to display and in what order.

Click “+” button within the Fields area and add Node: Title type of the field for your block:

clip_image008

Check the Node: Title from the list of the available fields and click Add button at the bottom of the page. Configure this field:

clip_image009

Check Link this field to its node box and click Update.

Add Filters for your block.

Filters are what are used to reduce the result set of a View to a manageable amount of data. They are a critical part of the foundation of this system.

The filtering system is a compromise between flexibility and ease of use. To be truly powerful, filters should provide the ability to do an OR, but as it stands, these filters are all ANDed together. That means that every filter is applied. While the ability to do an OR would be nice, unfortunately the level of complexity in the interface to do that is well beyond the benefit that would be given.

The order of filters is irrelevant, though they can be re-ordered as a convenience.

Then specify a filter for your block. Click “+” button within Filter area and add Node: Type filter:

clip_image010

Click Add.

Configure filter Node: Type:

clip_image011

Check Page as a Node type and click Update.

Then add Node: Published filter and select Published – Yes when configuring it.

Add Sort Criteria for your block.

The sort criteria on a View controls the order in which views results are presented. In general, sort criteria are specified by a direction, and the order is important.

Click “+” button within the Sort Criteria and check Node: Post date item:

clip_image012

Click Add.

Configure the selected criteria in the following manner:

clip_image013

And click Update.

Change Items to display from the default 10 to 5 items within Basic settings:

clip_image015

Click Update.

Select a Block View for your block.

A block view will appear as a ‘block’ on your site, meaning it can be put into the sidebars, or any other region your theme supports. The same view can provide both ‘block’ and ‘page’ views and they can have very different characteristics.

Set Defaults to Block:

clip_image017

And click Save button at the bottom of the page. We’ve done! Now you block appears in the right-side area of the page.

However, you can change allocation of any block (read more: http://www.templatezine.com/2010/01/how-to-allocate-blocks-on-your-drupal-based-web-site/)

One Comment »

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.