Archive for the ‘PHP’ Category

Theming fields in Drupal 6

I needed to figure out how to theme a field in Drupal 6. The use case was that I wanted to field to be a URL. This is pretty simple and straightforward by using the CCK Link module, which is a sub-module of CCK.

I was able to input my URL, such as with no problem, and the CCK display options are pretty good. However, I wanted to strip the “http://” part on the output display, but have the link remain the legitimate link of

CCK Link Display field

Though, there are several options for outputting the display in the Admin/Content Type//Display fields, there is nothing that handles stripping some characters from the title.

So I figured that I needed to theme the custom field. I searched and far and wide and found that though the documentation was present, there wasn’t much of it and it wasn’t that clear.

Here’s what I did.

My field name was called artistwebsite, so I needed to make sure that there was a standard content-field.tpl.php in my theme’s directory and then copy/clone that and call the new file content-field-field_artistwebsite.tpl.php. This works like other types of Drupal entity template files, but the tricky part is that you need to find content-field.tpl.php into your theme’s directory, because it probably isn’t there by default, depending on your theme.

I now have the following in my theme directory, and a field called field_artistwebsite in my content type.

I was able to re-write the output of a CCK Link field so that it removes the “http://” on the display title on the node.

I did this by adding the following lines of code in place of the commented out print statement below:

/* Here is the original PHP print statement line in the stock/default content-field.tpl.php
*  file that I commented out and replaced with what is above.

How to format line breaks in custom fields in WordPress

I was working on a WordPress project where I needed to create some custom fields and format them for the user. I wanted to be able to create those fields so that the user only had to put a few bits of text into the fields and be done with it without having the need to know any HTML formatting.

I had this working fine for two fields called price and dimensions. The issues was that the output is a line of text, so all of the items were being displayed on one line and then wrapping to the next line even though there were page breaks in the fields themselves.

For the price field.
$159.99 for two nights.
Add one more night for $49.99

The output looked like:
$159.99 for two nights. Add one more night for $49.99

I fixed this in the page template file by adding the following code around the get statement.


So my statement looked like:

ID, 'Price', true)); ?>

Now the output looks like I want:
$159.99 for two nights.
Add one more night for $49.99

Drupal Custom Breadcrumb visibility PHP code

I needed to show a custom breadcrumb on specific pages by URL.

The nodes in question were of “page” content type.

The URLs of these nodes were like:
/green/page3 and so on.

I only wanted the custom breadcrumb to show up on:
and not on /green

I created a breadcrumb with title “Green” and path “green” and used this PHP code for visibility:

$p= explode('/', $_REQUEST['q']);
return ($p[0] == 'green' && $node->nid != 79);

where 79 is the Node ID of the /green page.

I was able to get the desired result!

Note to self: print_r statements are your friend

Debugging a Drupal theme this early morning and remembered that using a print_r statement can provide all of the variables in a debug format for you.

print_r(explode('/', $alias));

I’m going to learn PHP, any good tips on doing so?

A few weeks ago, I posted about the fact that I had been laid off.

I live in Hong Kong and Domino/Lotus jobs don’t seem to be prevalent here at the moment.

In the meantime, I’ve taken time to “re-charge” my batteries and spend time with family and catch up on some todos around the house that had been procrastinated on for some time.

Now that I’ve got some time to focus, I have decided to learn PHP. I have thought about it for a very long time, but have never made the time to do it.

I figure that I’m excellent with server and infrastructure management and the tools to manage the infrastructure, excellent with Domino management and support, but lacking in any programming areas.

I do tend to do freelance work on the side, away from the corporate environment that are usually LAMP (Linux, Apache, MySQL, and PHP) type projects. This entails usually setting up a Drupal site, or similar open source PHP web application and hacking the CSS and theme to get it looking right.

I am familiar with working “around” PHP, but not a master at writing or even editing it.

I’ve starting looking into the online resources that are available and it looks like there are some really good free resources, both tutorials and video tutorials.

I’m just wondering if there is anyone out there that can give any good starting advice for someone that is more of an all around IT management person and is used to mostly keeping servers, up, configured, and running that does not really have any programming concepts experience.

Also, I’ve started looking at the Zend Framework for PHP. I’m wondering if that really is a standard for developing PHP applications.

One thing I’m wondering is why you would not use the Zend Framework? It seems like a no brainer to use it especially if you were developing something from scratch.


I'm currently available
for Lotus Notes / Domino consulting engagements.


Connect with me: