Many Faces of TimRSS Icon

CCK & Views the ultimate combination - part 2

Hi there, this post was originally on Venture Skills blog which is now defunct, but I have moved it over here to save it from vanishing forever. However I haven't done anything other then copy and paste so their maybe formatting or broken links. Also note comments will be switched off by default on these posts

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.

Quickly Linking?

If you want to link to this post quickly please use: http://tnash.eu/t416

alternativly use one of these services Tiny URL | bit.ly |is.gd

RSS feed

11 Comments

Comment by IbnKuldun
2007-02-09 17:35:38
IbnKuldun avatar

part 3 part 3 part 3 part 3…. :)

 
Comment by Venture Skills Team
2007-02-10 00:08:49
Venture Skills Team avatar

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

 
Comment by Blair
2007-03-22 15:18:11
Blair avatar

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.

 
Comment by Blair
2007-03-22 15:34:00
Blair avatar

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 :)

 
Comment by pete
2007-03-25 22:32:45
pete avatar

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.

 
Comment by Venture Skills Team
2007-03-25 22:40:53
Venture Skills Team avatar

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!

 
Comment by pete
2007-03-27 15:58:55
pete avatar

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!

 
Comment by Jin
2007-04-13 11:01:08
Jin avatar

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!

 
Comment by kemi
2007-09-16 05:38:02
kemi avatar

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

 

Responses to this post:

Sorry, the comment form is closed at this time.

Tim Nash consulting