Drupal 6

User login

Custom submitted by in tpl files

Here is a line of code to override Drupal's submitted by elements in node.tpl.php file.

<span class="submitted">

Draw circle overlay in all points in gmap from Radius in a CCK field | Dynamic gmap Macro in Views

Lately I needed to add a circle in every marker in a gmap provided by Views.

So in order to achieve this, I filled in the Macro textarea of the Style:Gmap settings of the View with the following code. But first, I added the field that contains the Radius value and excluded it from Display, to make the value available in the view result set. This value was in miles, so I made the conversion from km as well.

Show taxonomy terms Grouped By Taxonomy Parent

Lately I was assigned with the task to display all terms assigned to a node, grouped by their parent. To better explain this, let's say for example that we have the Vocabulary 1 assigned to Content Type A, with the following terms:
 
Parent 1
-- term 1
-- term 2
-- term 3
Parent 2
-- term 4
-- term 5
Parent 3
-- term 6
-- term 7
etc. 
 
Nodes from Content Type 1 have various terms assigned. For example, node/143 has the following terms assigned: term 2, term 4, and terms 6 & 7.
 

Show Blocks only on user's pages and not on login, edit etc. pages

If we need to display a block in user pages, and not in /user/login or /user/register etc pages, we need to field in some custom php code under the Page specific visibility settings, we select the radio "Show if the following PHP code returns TRUE (PHP-mode, experts only)" and we fill in the following code:

How to install drush

In this example, we will install drush under the directory /usr/local/share/. The path is not really important as long as you adjust the following commands accordingly.

If the directories do not exists, we create them:

sudo mkdir /usr/local/share/
sudo mkdir /usr/local/bin/

And now it time to download and extract drush. Make sure that you have the latest version available and replace the url in the command accordingly.

We also create a symlink so that we can use it everywhere without typing the parent path all the time...



Views: Display all nodes that have sibling terms (i.e. terms under the same parent) .

While working on an extra requirement for metalera.gr, we needed to do the following:

When viewing node/xxx, we would like to display all nodes that have terms that belong to the same parent as the one we currently visit. Let's say for example, that we have the following parent:

Colors

--red

--blue

--green

Node/xxx has the term green assigned. We need our view to display all nodes that have red or blue as well. 

To achieve that, we first create a new view, then:  

Views: How to exclude current node from output

In Drupal 6 there is a very easy way to exclude the current node from the views output. 

Drupal: How to generate different view results, using a taxonomy keyword as an argument

The following would apply if you wanted to generate nodes according to a specific taxonomy term, but you didn't want to create a different view for each case.

For instance, we have a market place and in the preface region of our theme, we've setup a 3x3 panel, and in each of the 9 dials we want to demonstrate the latest product from a specific category.

We would create a new node type(Product) for our market products, and a taxonomy vocabulary(Product Categories), which we would then asign to the aforementioned node type. Finally, we would create a view with the following options:

Drupal: Run simple JS Scripts on a specific node

Let's say that you have a simple input form, on a specific node in your drupal site and you just want to reset it, using a button. There are a few ways you could go about it, but this one is probably the simplest one.
  1. Initialize global variable $base_url to gain access to functions base_path() and path_to_theme(), so that you can generate the script's path dynamically.

Drupal time ago function in template.php

Would you like to make time appear as an interval like "4 days 3 hours ago"? Possibly you have worked with such formatters (drupal time ago) in views and date fields, but what about editing a node.tpl.php for example? Or programmaticaly include the last login time of a node's author, as time ago, in a block?

It comes in handy when there is a reusable function to format our time statements as drupal time ago - and php in general. So here comes a little function to be included in the template.php file. You can easily use it in your themes to display a timestamp as "Time ago".

Pages

Subscribe to Drupal 6