Difference between revisions of "Gallery2:Themes" - Gallery Codex
Personal tools

Difference between revisions of "Gallery2:Themes"

From Gallery Codex

 
(adding links)
Line 51: Line 51:
  
 
Click the "install" link then the "activate" link and 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!
 
Click the "install" link then the "activate" link and 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!
 +
 +
==External Links==
 +
* [http://marc.theaimsgroup.com/?l=gallery-devel&m=111882332024437&w=2 Bharat's initial proposal] on the theme refactor
 +
* [http://marc.theaimsgroup.com/?l=gallery-devel&m=112072316005756&w=2 Mail to the development mailing list] explaining the changes made.

Revision as of 15:43, 22 July 2005

Template:Expand

Creating a new theme

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 the matrix:

 cd gallery2/themes
 cp -r matrix mysite

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

 class MatrixTheme extends GalleryTheme { 

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

You need to change every reference to matrix to mytheme so that it looks like this:

 class MySiteTheme extends GalleryTheme { 

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

Further down in this file there is a function called upgrade(). You can delete this entire function.

A few notes about this:

  • 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.
  • 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.

Now, go to the Site Admin and select the Themes option from the left sidebar. Click on the "All Themes" tab and you should see your "My Site" theme show up in the list.

Click the "install" link then the "activate" link and 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!

External Links

advertisements