Pages

Wednesday, September 5, 2012

How to make a photo gallery with thumbnails in Drupal


Here we will create a simple photo gallery for Drupal CMS that will have thumbnails listed in a table with 3 columns. First of all, please have a look at how our final result will look like:
Would you like to have something like that on your website? Read on…
The way I made this photo gallery is kind of a hack, or workaround. It might not be the right way of doing it, but IT WORKS, which is the most important thing.
1. Enable following modules: Image, CCK, Views, CCK Nodereference, Path, Pathauto
2. Go to Image settings in admin section and set the options just like on the following picture and save configuration:
Capture1.jpg
3. Create a new content type “Album” with just “title” field enabled. We will just need to enter title for our albums.
4. Go to Pathauto setup and set following options:
For “Pattern for all Album paths:” put “gallery/[title]”
For “Pattern for all Image paths:” put “gallery/[title]”
Save configuration.
5. Create a new view and name it “album_list”, check “Provide Page View”. For URL you can put anything you want. For view type select “Table view”
  • In fields section, add field “Node: title”
  • In filters section add filter “Node: type” and select operator “is one of “ and for value select “Album”.
  • Add filter “Node: published”, for operator select “Equals”, for value select “Yes”
  • Click Save. Now we have our view that we will make a reference to.
  • Go to admin -> content types -> Image
  • Click “Add field” tab
  • Give it a name “album”, and for Node reference select “Select List”
  • On the next screen, for label put “Album”, check “Required”
  • Click on link “Advanced - Nodes that can be referenced (View)”, and for View select “album_list” from dropdown list.
  • Save field settings
6. Now, go on and create a new album”… Create content -> Album. Name it whatever you want, for example “My photos”.
7. Extract the archive attached to this article. There are 2 files “node-album.tpl.php” and “node-image.tpl.php”. Make sure you upload them to your themes/your_theme directory.
8. Now we will add some images to your album. Go to Create content -> Image. Click “Choose” to choose your image. For Album, select the name of your photo album that you have already created ("My photos" or whatever).
9. When you create your image, it will take you to something like
http://www.iwant2visit.net/gallery/amsterdam-1 . The last part of URL is the name of your image.
10. Keep on adding images to your photo album. Don’t forget, every time you upload an image you have to select name of the album that a new image will belong to.
Now you can have as many photo albums as you want and as many images as you want.
You can also experiement and make those pathauto settings to suit your own needs.

How to make Drupal piece of content that refreshes itself every 24 hours


This Drupal tutorial is easy, yet it can come very handy and useful sometimes. For one website, I needed to make one part on the frontpage to display teaser of random article, and refreshes itself every 24 hours. Easy, I thought, I could use block_cache module and that's all. The thing is, I am not using this block on sidebars, I need to display it on the frontpage, and on the specific part of the page... That means I need to display block from the template directly.
After some research, I found out about one module that is called insert_block. Its function is to insert contents of any block from your templates. Of course you can do this with Drupal API, using php code, but this is much easier, and safer.
So, we're going to use a combination of views, block_cache and insert_block modules to display our random content in a block that refreshes itself every 24 hours. This could be useful, for example for your frontpage, to have a "featured article", that will change every day.
Take a look at Overcome anxiety and depression website . At the frontpage in the lower right part, there is a "featured article" That is actually a block that is using one view that randomly selects one article and displays it using insert_block.
I will assume you already have some articles on your website.
1. Enable modules: Views, Block Cache, Insert Block.
2. Make the following view:
  • name it "feat_article"
  • check "Provide Block", view type is "Teaser list"
  • nodes per block: 1
  • in Fields section add "Node: Title" and Node: Body (teaser)
  • in Filters section add "Node: type" is one of "Page" (or whatever your type is) and "Node:published" equals to "yes".
  • in "Sort criteria" select "Random" from dropdown menu, and add criteria.
  • Save your view.
3. Go to Administer > Site configuration > Input formats
4. We will use "Full HTML" input format, so click "Configure" next to "Full HTML"
5. In Filters section, check "insert block filter" and Save configuration.
6. Now, go to Administer > Site building > Blocks. Find block "feat_article [[-CACHED-]]". Click "Configure". Uncheck everything and for the "Cache lifetime" put 86400. That is the number of seconds our block will refresh itself. 86400 seconds = 24 hours. So our block will refresh itself every 24 hours. If you need different interval, just find out how many second it is and put it in. Save block.
7. Find out what is delta number of "feat_article [[-CACHED-]]" block. Hover over "configure" link next to "feat_article [[-CACHED-]]" block and see the number at the end. Write down that number, you will need it in a second.
8. Go to your template where you want to insert this block. For the frontpage I use regular page content type. The syntax for inserting a block is:
[block:name of module=delta of block]
So if your delta number of block is 20, your syntax would be:
[block:blockcache=20]
For input format select "Full HTML".
9. Save everything.
Now you should have your piece of content refreshed every 24 hours automatically. The more nodes you have, the better. It will randomly select one node and display its teaser for the following 24 hours. It's pretty cool stuff.

Tuesday, September 4, 2012

Using tags and tagclouds to describe your content in Drupal


Tags and tagclouds are all over the web nowadays. Almost every blog or website has it. Setting up a tagging system in Drupal is very easy. If you are using Drupal as a weblog, this might be a great feature for your website. Heck, it is a great feature even if you're not using Drupal as blog.
First, let's see what tags and tagclouds are. Tag is like a description. Itdescribes some piece of content. So, if you were writing a page about your summer holiday in Greece, you would "tag" (describe) that page with these tags:
vacation, holiday, summer, Greece...
Well, you get the idea. The point is, you can put as many tags as you want. In other words, you can describe your content with as many words as you can. That way people can have an idea of what your article is about before they even read it.
Look at this article at the top (or any other article on this website). It has several tags associated to it. And also, there is a "Tags" block on this website, which lists all the tags that I have used to describe all articles. It makes a so-called "tag-cloud".
ok here we go :) Enough theory, let's set up tags and show that wonderful tagcloud :)
  • Go to Administer > Content management > Categories. We have to add new vocabulary for our tags. So, click "Add vocabulary".
  • For "Vocabulary name" write "Articles". It makes sense to name our vocabulary "Articles", because we are writing articles on our website.
  • Under "Types", select type of content that you would like to associate with this vocabulary. In my case it is "Page" type of content.
  • For "Hierarchy" select "Single".
  • Check "Free tagging".
  • I would recommend you check "Required" as well. That way you will be forced to "tag" every node you create for the content type you've selected. If you are tagging, then tag'em all :-)
  • Click Submit
  • Download and install Tagadelic module for Drupal.
Now, when you create some articles, and when you tag them, your content will be described or "tagged". Tagadelic module will automatically create block for every vocabulary that you are free-tagging. So if you go to "Administer > Site building > Blocks", you will find block named "tags in Articles". Go ahead and make it visble somewhere (left or right sidebar).
There! Now your tagcloud is ready. What's cool about tagadelic module is that it gives you tagcloud with tags that are displayed with fonts of different sizes - according to their "weight". Weight is actually how many times you have used a tag to describe a content. The bigger font size is - greater weight a tag has, which means you have used that tag a lot.
As you are adding more and more articles, meaning as you are tagging more and more content, your tagcloud will be automatically updated with weights. It's pretty cool stuff. Also, don't forget to play around with Tagadelic settings in Administer > Site configuration > Tagadelic configuration.
Happy tagging!

What is important when it comes to Drupal web hosting?


How to find good Drupal web hosting? Well, just like any other web application, Drupal requires that you have PHP support and access to MySQL database (PostgreSQL is also supported by Drupal). However, this is not enough for Drupal to run smoothly. You need several other things to have on your hosting in order for your Drupal website to run without any problems:

- Drupal is best if you run it on Linux platform. Personally I suggest you to go for Linux based web hosting, because it is much more stable and secure than Windows hosting.

- Easy to use Control Panel that will allow you to create new databases and do everyday tasks. Usually all web hosting companies will give you cPanel, which is a pretty good Control Panel system.

- Your web host should allow you to easily create, modify or delete existing databases and change permissions on those databases. This should be done inside Control Panel.

- phpMyAdmin script installed so that you can easily manipulate data in your existing databases, execute queries on your own and backup your databases.

- Drupal requires cron job set up on every 24 hours in order to run smoothly. This one is very important for your Drupal website, as Drupal must perform certain actions automatically every 24 hours (or often). So it's important that your web host have cron editor where you can set up your own cron jobs.

- Next you need a very fast connection to the database. This is because Drupal heavily depends on database system and have many queries that need to be executed very fast. The web hosts that I recommend all provide you with fast connections to the database system.

- You need excellent customer support. As always, you may run into problems with your Drupal installation or you just might have questions that need to be answered. Excellent customer support is a must when it comes to Drupal web hosting.

- The ability to host multiple domains on 1 hosting account. This is very attractive feature of Drupal. You can have as many web sites using only one instance of Drupal web application. This means that every domain will use its own database, but all domains will use one same instance of Drupal. This way you save on your web space. This feature is really cool if you want to have many Drupal websites on 1 hosting account.