Drupal Theming

Truncate A Drupal View Node Title

UPDATE

It appears that I missed the very obvious solution to this problem (!) which, as pointed out by a couple of commenters, is to use the ‘Trim this field to a maximum length’ option within the settings for the node title field.

I’ll leave this post in place as I think it still serves as a useful guide on how to create template override files for views, but please be advised that for implementing truncation of a views node title it is easier to:

  • navigate to the view's 'Edit view viewname' page (/admin/build/views/edit/viewname) and click the ‘Node: Title' link
    Truncate Drupal view node title
  • check the ‘Trim this field to a maximum length’ checkbox, and adjust the settings as required
    Truncate Drupal view node title

Creating Custom Regions In Drupal 6 Themes

Previously, I covered the topic of creating custom regions in Drupal 5 themes. However, Drupal 6 introduced a new process for creating custom regions in themes and it is still one of the topics people ask about most frequently.

So, here's a tutorial on how to create custom regions in your Drupal 6 themes. In this example I will use the Garland theme, and insert a new region called 'Uber content', which I'll position above everything in the main content area.

Custom Drupal 6 theme region

It's basically a two-step process:

  • step 1 - define the custom region in your theme's .info file
  • step 2 - insert some PHP in your theme's page.tpl.php file wherever you would like the new region to appear

Using PHP In Your Drupal Theme's Footer

The problem:
Drupal’s default 'Footer message' area (to which you can add content via the admin section - Administer > Site configuration > Site information) will not parse PHP.

If, for example, you add a copyright message to your footer message area such as "© Copyright 2009" it'll be fine until the New Year begins and you have to go in and manually change it to "© Copyright 2010". So, instead, it would be great if you could handle the date dynamically using the following PHP code (see http://php.net/date for further PHP date details):

© Copyright <?php echo date('Y'); ?>

However, try adding that to the default 'Footer message' area and it will simply output the entirety of the code as text, ignoring the PHP tags.

No PHP in a Drupal footer message

So, what to do?

Solution 1:
Create a block (admin/build/block/add) containing the code, set its input format to PHP, and then place that block in the footer region via the main blocks settings page (admin/build/block). Crazy simple.

My Drupal Blog RSS Feeds Updated

Just a quick note to say that the My Drupal Blog RSS feeds have been updated.

The local URLs are still the same:
Posts - http://mydrupalblog.lhmdesign.com/rss.xml
Comments - http://mydrupalblog.lhmdesign.com/crss

But the FeedBurner URLs are now slightly different:
Posts - http://feeds2.feedburner.com/MyDrupalBlog
Comments - http://feeds2.feedburner.com/MyDrupalBlog-Comments

Been A While!

Work, work, and more work have meant that I’ve rather neglected this blog as of late. But no more! Content is a-comin’ (slowly ;) ). And just a quick heads up for any comment RSS feed subscribers - I know that the feed is borked, and I may have to temporarily disable it whilst I resolve the issue (if, of course, I can access the Feedburner site, which is currently down). Fun times!

Drupal Theming News

There are two big Drupal theming discussions happening right now, which I'm sure a number of you are aware of, but for those who aren't here's a quick summary:

1. Project Plan For A New Default Drupal 7 Theme
First up, lots of interesting stuff regarding the Project Plan for a new default Drupal 7 theme.

Right now this is a wiki page with an 8 step plan addressing the question of 'How do we get a new default theme in core?'. Step 1 'Create a project plan' has its due date set at November 7, 2008 so get in there quick!

Also, it looks like there will be a theming contest to create Drupal 7 sub-themes for core, once the new base theme has been finalised, which I'm sure will be of interest to a number of themers out there.

2. Drupal.org Redesign
Secondly, lots of discussion regarding Prototype Iteration #5 (including initial visual design direction) of the drupal.org redesign, which has gone online here.

Comments, discussion, suggestions etc. are welcomed by the authors on both of these topics.

Drupal API Dreamweaver extension important update

Just a quick note to say that Chris over at xtnd.us contacted me recently regarding the updated Drupal API for Dreamweaver extension.

It's now in beta 2 with a full release expected for Q4 2008, and according to Chris "code coloring works, plus Dreamweaver can understand Drupal file types naturally now - like .module, .info, .theme, .install, etc."

You can find links to other xtnd.us Drupal products here.

Build An Aggregation Site With Drupal (Part 3)

Previously...
In Build An Aggregation Site With Drupal (Part 1) and Build An Aggregation Site With Drupal (Part 2) I covered setting up the foundation of your aggregation site using Drupal and SimpleFeed and then using cron to auto-update content and views to create the site sections and RSS feeds for our content.

In this third part of the series I'll look at theming the news items, and finally in part 4 some extra touches including filtering options for our users. You can check out the finished aggregation site (parts 1, 2, and 3) here.

Step 1: Set up the new theme
So far during this tutorial series I've been using a clean install of Drupal with the default Garland theme enabled.

Now that we'll be making various changes to the site's theme it's best to set up a new version of Garland in your site's sites/all/themes folder which you can then enable and edit instead of the default Garland theme (which is located at themes/garland) thus keeping the original Garland theme intact.

Build An Aggregation Site With Drupal (Part 2)

Previously...
In Build An Aggregation Site With Drupal (Part 1) I covered setting up the foundation of your aggregation site using Drupal and SimpleFeed. In this second part I'll cover using cron to auto-update content, and then look at using views to create site sections and RSS feeds for our content.

Step 0: Before we start
There is currently one flaw in the SimpleFeed module which we need to correct before continuing. Sometimes taxonomy terms are not assigned automatically to aggregated items, which will stop our site from functioning properly. You can find a more detailed discussion about this issue here.

The good news is that it has been fixed in both the 5.x and 6.x branches and is easy for us to correct :)

Just download the new Drupal 5 version of the updated simplefeed_item.module file from CVS and save it over your current simplefeed_item.module file which you will find in your SimpleFeed module folder (sites/all/modules/simplefeed/simplefeed_item.module).

Step 1: Cron
Adding cron functionality to an aggregation site is pretty crucial because without it our content will not auto-update. We could technically update our feeds manually but that would be a very tedious process, so cron is definitely the way to go!

Build An Aggregation Site With Drupal (Part 1)

This tutorial will be split into three parts - part 1 (this part) will explain how to set up the aggregation and import feeds, part 2 (to be published next post) will explain setting up cron to handle auto updating the feeds and will also cover using views to create some different site sections, and part 3 (to be published the post after that) will explain how to theme everything. In the tutorial I will be building a Drupal based sports news aggregation site, but you can obviously tailor this to whatever type of news items you'd like.

The goals:

  • Create an aggregation site which aggregates RSS feeds and outputs them in river of news style pages with the most recent news items first.
  • Create some different site sections (football and baseball) which only show news items related to that topic.
  • Allow users to filter news items by source (e.g. ESPN, BBC etc.).
  • Create RSS feeds of our aggregated pages which are available for our users.

You can check out the finished aggregation site (part 1 + part 2) here.

The set up:
For this tutorial I'll be using the following:

  • A clean install of Drupal 5.10 (using Garland)
  • SimpleFeed 5.x-2.2
  • Views 5.x-1.6