Services

  • Drupal CMS Developer
  • Website speed optimisation
  • Drupal 6 to Drupal 8 migrations

Welcome

Welcome, I am a Web Developer based in Madrid, Spain originally from the UK. I studied Computer Science & eBusiness at Loughborough University. I specialise in Content Management System websites

Will's Scripts & Functions

Below are some of the snippets of code that I have found useful over the years. Most of them are available and better documented on php.net or respective API sites but I have collected together some of the more common ones that I use or took a long time to find.

 

 

Use the filter form below to filter the scripts and snippets by category...

Place a link to a view page next to the node edit link

I was trying place a link to a views page in the tabs that appear on nodes, I wanted it to appear link "Node Edit MyNewLink". The way to do this is to set the page URL "node/%/MyNewView", and create a normal "menu tab". The link will automatically appear, just make sure you replace "MyNewView" in your view path to something relevant.

Display signature in User profile page

I was really surprised that Drupal as standard did not show the user signature on the user profile, it doesn't even give you the option! It's really simple to do if you know how but took me a while to figure out.

You must create a module (see drupal documentation for doing that) and paste the following in...

function MYMODULE-NAME_profile_alter(&$account) {
$account->content['summary']['signature'] = array (
'#type' => user_profile_item,
'#title' => t('About the writer'),
'#value' => $account->signature,
'#weight' => -1,
);
}

Views 2 - Don't list / Exclude current page

If you want to create any normal listing based on category or content type and say have it appear in a block across several pages, but want to make sure that the page you are currently on doesn't appear in the list, then the below should help
Instructions made from a collection of information found in Drupal website...

1). Open up your view
2). Create an argument of Node > Node id.
3). Then choose the radio button option of "Provide default argument"

My Drupal 6 block template file doesn’t work

I had the problem whereby I wanted to change the theme layout of the locale bar. The devel module told me to use the template file “block-locale.tpl.php” but when I created this file and populated it with dummy information, it did nothing. I tried clearing the cache and still could not get it to change the content of the locale block.

In the end I found out that if you do not have block.tpl.php (example code below for you to start with) in your theme then block-locale.tpl.php gets ignored.

Resetting owner of files Linux

chown user:group -R *

recursively resets all files the the ownership "user" in the group "group" for all files and folders in current working directory and and sub folders.

Drupal WYSIWYG stops working with my new template

I work on the technical side of Drupal and my colleague works on the design part. At one point in time (without realising when), our WYSIWYG editor stopped working and no others would work in its place. We were using HTMLArea/Xinha but tried the YUI as well as the FCKeditor without any luck.

The strange thing was that the WYSIWYG editor would appear in the blocks edit page but not when creating/editing a page.

Drupal htaccess for SEO friendly URLs (clean URLs)

I have had some issues myself with drupal websites and getting the SEO friendly URLs to work when I either have no access to the server or the server changes cannot be made (CPANEL does cause a problem)

Attached is a copy of an htaccess for Drupal 5 and 6 that you can use….

Mysql delete duplicate rows

The script removes only one duplicate entry at a time, you have to run it several times to remove all duplications (I advise running it in a php script which then counts duplicates left afterwards) or just run it recursively whilst testing for duplicates. As ever, remember to backup your database first!!!

DELETE tablename
FROM tablename,
(SELECT MAX(uid) AS dupid,COUNT(uid) AS dupcnt
FROM tablename
GROUP BY id,url HAVING dupcnt>1)
AS dups
WHERE tablename.uid=dups.dupid;

Replace string in a table

If you want to change certain rows in a database where a query applies … for example an “if” query finding all entries which contain “samplesearchtext”… then run the following script either via mysql/phpmyadmin/php

<?php
mysql_query
("update mytable set myfield =replace (myfield, 'samplesearchtext', 'samplereplacetext')");
?>

Shorten string length

<?php
// substr(input,start point,length)
$query = substr($query,0,-1);
?>

Shortens the string by one character. Change the second value to remove more or see php.net/substr for more information