HOWTO - Gallery2 Matrix theme with Google AdSense support

Patch Gallery2

This is very important!

Without this change your image/album list looks very ugly (3 x 3 plus one additional image).

Open modules/core/classes/GalleryTheme.class under your gallery2 directory and find function getPageSize. In original it looks following:

    function getPageSize($params) {
        if (!empty($params['rows']) && !empty($params['columns'])) {
            return $params['rows'] * $params['columns'];
        }

        if (!empty($params['perPage'])) {
            return $params['perPage'];
        }

        return 0;
    }

Now, swap these two if statements like this:

    function getPageSize($params) {
        if (!empty($params['perPage'])) {
            return $params['perPage'];
        }

        if (!empty($params['rows']) && !empty($params['columns'])) {
            return $params['rows'] * $params['columns'];
        }

        return 0;
    }

Option 1: Manual installation

Install original Matrix theme

Matrix theme is included in Gallery2 full installation. If you don't have full installation, download original theme here:

Download patch

You can find MatrixAd patch here: http://www.version6.net/patches/matrixad-1.1.4.20070527.diff. Download and save it to /tmp directory.

Duplicate original theme and add patch

cd gallery2/themes
cp -a matrix matrixad
cd matrixad
patch -p1 < /tmp/matrixad-1.1.4.20070527.diff

You can also replace images/screenshot.png with http://www.version6.net/patches/screenshot.png

Option 2: Download theme package

Just download MatrixAd theme here:

and unpack it to your gallery2 directory

Make your local modifications

Go to matrixad/templates directory

Google Analytics

If you have Google Analytics account, you can add its content to google-analytics.tpl like this:

{php}
$adcode = <<<END
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-xxxxxxxxx";
urchinTracker();
</script>
END;
echo $adcode;
{/php}

If you don't you can leave it untouched or remove this line form theme.tpl

{g->theme include="google-analytics.tpl"}

Google AdSense

Use these files as base. Change google_ad_client if you like :-) You can also combine different text and image ads but keep size similar with my examples (btw, I use 15×150 thumbnails).

adsense_album_albums.tpl

Use here ad format 180x150_as like this:

{php}
$adcode = <<<END
<div class="ad-image">
<script type="text/javascript"><!--
google_ad_client = "pub-9817749736387012";
google_ad_width = 180;
google_ad_height = 150;
google_ad_format = "180x150_as";
google_ad_type = "text_image";
google_ad_channel = "";
google_color_border = "EEEEEE";
google_color_bg = "EEEEEE";
google_color_link = "6F8FB9";
google_color_text = "333333";
google_color_url = "6B8CB7";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
END;
echo $adcode;
{/php}

adsense_album_images.tpl

Use here ad format 180x150_as also. Only difference is backgound color:

{php}
$adcode = <<<END
<div class="ad-image">
<script type="text/javascript"><!--
google_ad_client = "pub-9817749736387012";
google_ad_width = 180;
google_ad_height = 150;
google_ad_format = "180x150_as";
google_ad_type = "text_image";
google_ad_channel = "";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "6F8FB9";
google_color_text = "333333";
google_color_url = "6B8CB7";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
END;
echo $adcode;
{/php}

adsense_head.tpl

Use here ad format 728x90_as like this:

{php}
$adcode = <<<END
<div class="ad-image">
<script type="text/javascript"><!--
google_ad_client = "pub-9817749736387012";
google_alternate_color = "eeeeee";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "image";

google_ad_channel ="0316106500";
google_color_border = "EEEEEE";
google_color_bg = "EEEEEE";
google_color_link = "6F8FB9";
google_color_url = "6B8CB7";
google_color_text = "ACACAC";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
END;
echo $adcode;
{/php}

adsense_sidebar.tpl

Use here ad format 200x200_as like this:

{php}
$adcode = <<<END
<div class="ad-image">
<script type="text/javascript"><!--
google_ad_client = "pub-9817749736387012";
google_alternate_ad_url = "http://www.version6.net/images/film.jpg";
google_ad_width = 200;
google_ad_height = 200;
google_ad_format = "200x200_as";
google_ad_type = "image";
google_ad_channel ="0316106500";
google_color_border = "CCCCCC";
google_color_bg = "FFFFFF";
google_color_link = "6F8FB9";
google_color_text = "ACACAC";
google_color_url = "6B8CB7";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
END;
echo $adcode;
{/php}

I used here static picture for alternate ad. It doesn't look nice if this place remains empty in case of missing ad.

Activate

Go to “Site Admin” → “Plugins” and install “MatrixAd” theme plugin. After that open “Themes” page and configure this as default theme or change themes for your albums in “Edit Album” → “Theme” page.

 
matrixad.txt · Last modified: 2007/08/02 12:51 (external edit)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki