Pages

Wednesday, September 5, 2012

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.

Wednesday, August 29, 2012

Drupal Website Building Tips - Part 6


Upload and download files

Whether a file is available for private or public download depends, of course, whether the page to which it is attached is available privately or publicly. In addition, there are methods for maintaining private download folders (for FTP or other access).

Public files / attachments

In general, files are "attached" to a page. See Uploading files with Drupal for information about changing permissions.
  • Attach a file to an existing page (examplepage):
Drupal -> Administer -> Content Management -> Content -> examplepage -> edit
-> File attachments -> Attach new file: your file to upload -> Attach -> Save

Increase uploaded file size limits

Add a quotation module

Add the Fortune module to Drupal

Fortune is a *nix utility to display quotations from preselected files. Drupal has a plugin to display these quotations from within a webpage. Although a nice module, a disadvantage is that it uses monospace font and currently does not have options to adjust the font type and size. See here for installation details.

Add the Quotes modules to Drupal

  • Download the Quotes module:
cd /etc/drupal/6/all/sites/modules
sudo wget http://ftp.drupal.org/files/projects/quotes-6.x-1.40.tar.gz
sudo tar zxvf quotes-6.x-1.40.tar.gz
sudo rm quotes-6.x-1.40.tar.gz
Note: If you wish this module to be available to only one subsite, then install it instead into the /etc/drupal/6/sites/mysite_x/modules folder.
Note: You must update and adjust permissions after module installation.
Drupal -> Administer -> Site building -> Modules -> Other -> Quotes (ticked) -> Save configuration
  • Create a Quotes content and import your quotations. You can create a quotation one by one, or a large number of Quotations all at once (from a file, for example). Each quotation is created as an individual content item. The "display in Quote blocks" option determines whether a Quotes block (created in the next step to display a rotation of the quotations) will include the particular quotation(s) created in this step.
Drupal -> Create content -> Quotes
->Name: Quote%id -> Display in quote blocks: (ticked)
I use quotations from the Fortune program, which are in a particular text file format that looks like:
I reject your reality and substitute my own...
%
This is one of those "What the hell am I doing?" moments, over!
%
We got a robot in the water, he's stuffed with tuna and it's just another day here at Mythbusters.
I copy the contents of the text file into the input box.
-> Format: Import Fortune file -> Comment settings: Disabled -> Save
This will create as many content items as are in the Fortune file. If there are hundreds of quotes, you will have hundreds of Quote content items.
  • Configure the Quotes settings so that Quotes can appear as a block:
Drupal -> Administer -> Site configuration -> Quotes
-> Configure blocks -> Name: Quotes -> Add block -> Configure block
-> Update options -> Update every 6 seconds
-> Show block on specific pages -> Show on only the listed pages: choose the pages to display on
-> Save block
  • Add the Quotes Block on your site:
Drupal -> Administer -> Site building -> Blocks -> Quotes:Quotes -> Location