Gallery2:Themes:How to Copy an Existing Theme - Gallery Codex
Personal tools

Gallery2:Themes:How to Copy an Existing Theme

From Gallery Codex

Adding or creating a new theme

To add a theme, move it to the gallery/themes folder. For instance, if you have downloaded a zip file, unzip it and move the unzipped folder that contains the theme to the gallery/themes folder. The folder that contains the theme will have the files "" and "theme.css" in it. There are many User contributed themes available.

The easiest way to create a new theme is by cloning a theme and then modifying it.

Cloning a theme

Pick a theme that is similar to the functionality that you want. We suggest that you start from one of the themes that comes with Gallery2 itself as those are usually the most current code. Your new theme will need a unique theme id. Ids are a single word that contains only alphanumerics and underscores and should be related to the name of your theme. So let's say that you're cloning the Matrix theme and making a new theme called MySite, you might give it the id mysite.

Let's start by making a copy of the matrix folder and all its contents, calling the new folder mysite. From a unix shell you can type:

 cd gallery2/themes
 cp -R matrix mysite

Or just use your ftp client to make a copy. For instance, you can copy the matrix folder to your computer, then rename it and upload it back to the server.

Now let's edit mysite/ to set the details for your new theme. Edit mysite/ and inside you'll see a block that starts like this:

 class MatrixTheme extends GalleryTheme { 

      * Constructor 
     function MatrixTheme() { 
         global $gallery; 
         $this->setDescription($gallery->i18n('Standard Gallery2 look and feel')); 
         $this->setVersion('0.9.9');  /* Update upgrade() also */ 

You need to change every reference of matrix to mytheme and adjust the description and version to be appropriate to your theme. These areas are marked below in bold:

 class MySiteTheme extends GalleryTheme { 

      * Constructor 
     function MySiteTheme() { 
         global $gallery; 
         $this->setName($gallery->i18n('My Site')); 
         $this->setDescription($gallery->i18n('This is a theme for My Website')); 

A few notes about this:

  • Delete the MANIFEST file in your new theme if it exists. It contains data from the theme you copied and can cause confusion when you upgrade.
  • You must use the same letters in the class name and function name as you use in the id, but the capitalization is not important in this sense.
    • Capitalization is important in that the $this->setId('mysite'); must be the same capitalization as the folder name of your theme, otherwise you will get an error saying that it couldn't find your theme, when trying to install it. (so stick with the capitalization you use in your folder name)
  • You can use whatever version number you want, but stick with the #.#.# format to make it easier for you to write your own upgrade code.
  • If the original theme has an upgrade function, you can delete it from your new theme (and add it back later when you start supporting upgrades)
  • Your theme name must end in "Theme" just as the matrix theme does.

Now, go to the Site Admin and select the Plugins option from the left sidebar. Here, install your new theme. Then, click on Themes in the sidebar. Now you should see your "My Site" theme show up in the list.

Your theme should now be available for use! Edit an album and select your theme from the list and you'll be using your own personal copy of the Matrix theme!