Tag Archives: php

Subtheming in Drupal is really easy

I just created a Drupal Subtheme in about 20 minutes!

If you like the look (mostly) of one of the exiting Drupal themes, you can easily add a few customisations by extending a theme rather than starting from scratch. This is also a good way to start the development of a from-scratch theme, as you can build up some CSS and new logos and colours without losing most of the functionality until you are finished coding it all.

The first thing to do is create the bare minimum required to activate your theme. Go to the sites/all directory, and create the themes directory (if it isn’t already there). In there, create another directory with the same name as your theme (the machine readable name, all lower case, as opposed to the human readable name, which we will specify later). The rest of these instructions assume that you named your theme “theme”.

Next, you need to create a theme.info file. Below is a sample:

; filename theme.info
; $Id$
name = Human Readable Theme Name
description = a simple example theme that depends on the marvin core theme.
version = 0.1
core = 6.x
base theme = marvin

This is really all you need to create a theme; you will get an empty logo (replaced by a link called “home”), and you will have the rest of the marvin theme there to play with. To insert your own site logo, just drop a logo.png into your theme directory and you are done!

You can then add a stylesheet, which will allow you to override the marvin CSS elements one at a time as you develop your theme further. Just add the following lines to the info file:

; for the default stylesheets:
stylesheets[all][] = style.css
; for your own stylesheet:
stylesheets[all][] = my-styles.css

Where to go from there is up to you! You have the full armoury of CSS styling available to you. I recommend something like Firebug (Firefox plugin) for finding out the names of the different CSS elements you want to change, but you can just dive straight into the marvin CSS files if you prefer.

In a future post I will explain how to take an existing scheme (page and CSS) and turn them into the base for a Drupal theme (which may be more useful to people who want to change their CMS, or borrow a theme that they saw that was cool).

MAMP / phpwiki

Today I got a personal wiki working in well under 2 hours on my Mac.

If you are a Mac user and would like an easy way to keep track of rough draft thoughts and your own personal memory jogging how-tos in a secure and simple way, I recommend the following:

  • Download MAMP (Mac Apache, MySQL and PHP)
  • Install by dragging to your applications folder as normal.
  • Use the myPhpAdmin web-software (available at localhost:8888/MAMP/) to configure your database server (mysql) to accept connections from a new user (phpwikiuser, for example) and add a new database for it (e.g. phpwiki).
  • Download phpwiki, and extract the archive using

    tar -xzf phpwiki-version.tar.gz

    (you may not need the z if the extension is just .tar, as safari automatically gunzips the file when it finishes downloading.)

  • Rename the folder to whatever you like (e.g. phpwikiname) and move it into the docroot (default is /Applications/MAMP/htdocs, but you can reconfigure it in preferences).
  • Finally, you will need to open the config file and enter the database login details for it, e.g.

    pico lib/config.php

    or whichever your favourite text editor. (If you just use textedit or word, then you can go to the location (e.g. /Applications/MAMP/phpwikiname/lib/config.php) in finder and double click on the file, choosing TextEdit if no default is set.)

  • Change the db type to mysql, and make sure that the database login details further down (in the mysql section!) match what you entered when you created the account. You could just use ‘root’ and ‘root’, but I would advise a less privileged user which only has permissions over the phpwiki database so it can’t break anything else you end up using MAMP for later.

Thats it! Navigate to localhost:8888/phpwikiname/ and edit your front page. Advantages of phpwiki are that it is small and light, has very simple creating and editing (just creating a link creates the page) and it does the job. It’s disadvantages (very insecure as anyone can edit and see who has been editing down to the IP address) are irrelevant if you are using them on a personal system, although you may prefer something a bit prettier (like mediawiki, which is what wikipedia uses; although I don’t use it because it is a sledgehammer to crack a nut for a personal wiki on your laptop – the instructions would be roughly the same though.).

That’s my 2 hours for today, tomorrow I will be covering the basics of theming a drupal web site.