CCK & Views the ultimate combination - part 2

Drupal is a fantastic content management system but is perhaps not the most non developer friendly however 3 simple modules can help you create compelling and powerful web site. So in this 3 part mini series lets see how easy it is to develop new content types and ways to view it. To help us lets use a fictitious company called AA Design who are about to start teaching a range of courses.

Quick note this post refers to Drupal 4.7 however several of these modules are now available for Drupal 5

Views


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

In the previous part we created our own content type node, using the CCK, we will continue this example and create a block and page that lists our content type in date order. Once again we start by downloading the views module from and installing it in our usual way, once installed you can find the views in adminster->views.

When the views module is installed it has several default views, however we are going to create a brand new one. To do this click the add tab, and give your new view a name and select both anonymous and authenticated users for access.
Next expand the page field set, and tick provide page view and give the view a node alias, it is referred to as url on the form but you need to provide only an alias such as latest.
Under view types select teaser list and give the page a title.
Now expand filters field set, and under add filter select node type and click add, once you have added the filter, select your content type from the list, and make sure the operator “is one of”.
Add a second filter this time select node published and the operator is yes.
Finally expand the sort criteria, under add criteria choose node created Time, and then choose order descending.
Now click save.

Now to add a block we need to go back to the view and edit it, this time we are going to expand the block section and tick the provide block, from the view type select list view. Under nodes per block put in a value I suggest 5 or more.
Next expand fields and add field selecting node title, make sure it has the option As Link selected and then save the view.
add the block in the normal way, it will be named the same as your view.

The Block should show the titles of your latest content which when clicked will go to there nodes and you should now have a page, which shows only your content in descending order. This was a simple example, look through the provided examples in the view module for more advanced views.

The final part of this series is about contemplate to help theme your new content type.

Other Articles in the Series
CCK & Views the ultimate combination -part 1
CCK & Views the ultimate combination -part 3
HReview a CCK example using contemplate

Get our Content via RSS feed using Feedburner
Other Articles on the Venture Skills Network about Drupal
Drupal 5.0 goes Beta
5 Drupal Modules to Guarantee Drupal 5.0 Success
The Digg effect and can Drupal survive it
- looking at how drupal can cope with bandwidth spikes
Want to create a site like Digg with no programming series

Subscribe to The Venture Skills Blog by Email

PodcastAll our Posts are audio subscribed for more information see here, and to access the podcast feed here


RSS icon This blog is moving soon, make sure you move with us by using our Feedburner RSS feed, if you have used the autodiscovery button in your browser you may need to swap feeds, simply delete the old feed and add, http://feeds.feedburner.com/VentureSkills For a more detailed explanation on feeds and recieving our content in various formats click here

Posted in Technology, drupal. Tags: .

11 Responses to “CCK & Views the ultimate combination - part 2”

  1. IbnKuldun Says:

    part 3 part 3 part 3 part 3….

    :)

  2. Venture Skills Team Says:

    Part three will be up over the weekend, just finishing it off, and proof reading, glad you enjoy the series.

  3. The Venture Skills Blog CCK & Views the ultimate combination - part 3 « Says:

    [...] 1 we looked at how CCK (Content Construction Kit) can be used to develop new nodes, while in the second part we discussed views for displaying your custom content along with other nodes. You may have noticed [...]

  4. Blair Says:

    I get the following error when adding the view:

    * warning: mysql_real_escape_string() expects parameter 1 to be string, array given in /home/photogra/public_html/includes/database.mysql.inc on line 400.
    * warning: mysql_real_escape_string() expects parameter 1 to be string, array given in /home/photogra/public_html/includes/database.mysql.inc on line 400.

    The view does save though. But then when I enable the block, it does not appear and the following error appears on every page of the site. The only way to get rid of the error is to delete the view.

    user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ”’ ;) ORDER BY node_created_created DESC LIMIT 0, 1′ at line 1 query: SELECT node.nid, node.created AS node_created_created FROM node node WHERE (node.type OR ” ;) AND (. ” ;) ORDER BY node_created_created DESC LIMIT 0, 1 in /home/photogra/public_html/includes/database.mysql.inc on line 172.

  5. Blair Says:

    don’t worry about the above. I made a mistake with the view. I forgot to specify the content type! It works like a treat now :)

  6. pete Says:

    Is this the most bone-headed way ever of providing this functionality? If I want to add it to my Drupal site, then I have to download not one, but THREE extra modules, and then spend an age twiddling and messing with settings within the Admin pages. Considering the amount of confusion that this generates, I see why Drupal is generally regarded as the red-headed stepchild of CMS’s.

  7. Venture Skills Team Says:

    lol I can sort of see your point Pete though obviously CCK and views are addons that provide extra functionality and as part of the CCK is integrated into Drupal 5 it now works much more out of the box, however Joomla and other blondie CMS’s have nothing that can compare with Drupal flexibility when you use CCK and views together.

    So yes to get this amount of freedom and flexibility you need two to three extra modules, but other CMS dont have anything to compete, and if you think the tweaking on Drupal bad, try the big boys fav Plone!

  8. pete Says:

    Okay, maybe I was having a hissy fit… and perhaps CCK and Views will naturally be merged into the core Drupal install in the future, because that would seem to make sense. BTW, thanks for writing up CCK/Views in an easy to understand way!

  9. Jin Says:

    I have worked with CCK and Views - this is great combination for sure, but have some problems with Views.
    Here it is:
    I installed Views module and activate 2 Views’ components: Views and Views UI. Then I tried your views-example (part2) and its work. Some I have got a problem, when I linked to some posts I get an empty (blenk) page with correct URL in address bar. I can’t enable Views-module in admin->modules page thanks for this problem and I have to delete it from module folder, manualy, and it help, all become normal. When I put Views to the module folder again my problem occur too, so it’s stable.

    Somebody can help me with that…? Please!

  10. The Venture Skills Blog CCK & Views the ultimate combination - part 1 « Says:

    [...] TipsCCK & Views the ultimate combination - part 1HReview a CCK example part 1 - ContemplateCCK & Views the ultimate combination - part 2Stumbleupon vs Digg - Page layoutsStumbling [...]

  11. kemi Says:

    When i use views and save my new view page comes up completely blank same for my new content type in cck. WHY?