Gallery2:How to add adsense - Gallery Codex
Personal tools

Gallery2:How to add adsense

From Gallery Codex

This article describes how you can include Google AdSense in your Gallery-powered website to generate revenue by displaying Google Ads.

This How to is made for the default Gallery theme (matrix).

There are several ways to include Adsense.

Add to Header - Method 1

First, FTP into your web site and create a new directory (folder) called 'local' in the templates folder of the theme you are using.

NOTE: If you are using the Carbon theme, you do not need to do any of the following. Scroll down to find your instructions. The Carbon theme already has Ads built in.

Then create a new .tpl file under /gallery2/themes/matrix/templates/local/

A quick an easy way to create a new .tpl file is to open up Notepad in Windows (don't use Word Pad as it will insert formatting) and type (copy) your code. When you go to save the file, just save it as .tpl instead of .txt.

I called this file adsense.tpl

Edit this file and insert the following code (insert it anywhere since this file will be blank):

{php}
$adcode = <<<END
HERE COMES YOUR 
GOOGLE BANNER CODE 
(its better to use 468x60 size)
END;
echo $adcode;
{/php}


Note: replace only the text between the first and second END with your Google Adsense code (in red). Do not replace <<<END or END;

Now you have to copy /gallery2/themes/matrix/templates/theme.tpl to /gallery2/themes/matrix/templates/local/ (create the directory if it does not exist) and edit /gallery2/themes/matrix/templates/local/theme.tpl

After the logo line (before </div>) add this code:

{if $theme.pageType == 'album' || $theme.pageType == 'photo'}
{g->theme include="adsense.tpl"}
{/if}

That's it! Notice that we test to make sure that this is a page that Google AdSense's crawler will have access to by default. If you use authentication just to view images, you will also have to configure Google's adsense service to be able to authenticate, but the above code will at least stop the ads from being displayed on admin pages.

you can see a live demo on my site

Kedem photos or mapmyphoto

--Omrik 08:44, 17 April 2006 (PDT)

Live demo: PBGallery --Paolo Brocco 13 July 2006

Live demo: MJ-Garage Gallery --JDuc 28 February 2008

Add to Header - Method 2

There is another way to add Google AdSense in Gallery2. You have to copy /gallery2/themes/matrix/templates/theme.tpl to /gallery2/themes/matrix/templates/local/ and edit /gallery2/themes/matrix/templates/local/theme.tpl.

You will most likely need to create the /gallery2/themes/matrix/templates/local/ folder.

Again, if you are using the Carbon theme, skip this stuff and scroll down.

Find:

<img src="{g->url href="images/galleryLogo_sm.gif"}" width="107" height="48" alt=""/>

After that add the Adsense code, if you want to center the banner you have to use

<div align="center"><--ADSENSE CODE--></div>

You can see a live demo on my site.

But there is a problem if you use the XP's Tool to publish photos from your PC you have to deactivate the code, you can rename /gallery2/themes/matrix/templates/local/ folder and after upload the photos rename again.

Note: this is not a problem if you use Method 1 above --Omrik 13:15, 3 May 2007 (PDT)

Add to Footer

You can add a Adsense Banner in the footer. Find the following code and add your Adsense code below that .

<div id="gsFooter">
	{g->logoButton type="validation"}
	{g->logoButton type="gallery2"}
	{g->logoButton type="gallery2-version"}
	{g->logoButton type="donate"}
</div>
{/if}  {* end of full screen check *}

Remember to use

<div align="center"><--ADSENSE CODE--></div>

to center your banner.

Add to Side bar

This will add a 120X600 Adsense Skyscraper in the Side Bar

Copy /gallery2/themes/matrix/templates/sidebar.tpl to /gallery2/themes/matrix/templates/local/sidebar.tpl and edit the newly copied file.

Below

 </div>

add your Adsense code for the 120x600 banner.

This will display the 120x600 banner in your side bar and blend it with the colors of the Matrix theme.

Carbon Theme

If you're using the carbon theme, you're in luck.

Open up your FTP program of choice and go to your /gallery2/themes/carbon/templates folder and find ads.tpl Copy this file to your desktop. Open it with your favorite editor of choice (you can use Notepad if you are in Windows XP) and READ THE TEXT THAT IS ALREADY THERE. Paste in your AdSense code and wrap it all with the following tags: {literal} {/literal}. Save the file as ads.tpl (which is already is) and upload to your /gallery2/themes/carbon/templates/local folder.

Voila! You're all done!

--JDuc 28 February 2008

for the carbon theme : in the thumbnail in the photo veiw :

example

http://www.pho2o.net/gallery/v/deeb/n649780189_136741_6625.jpg.html

go to your gallery ftp or cpanel

open file manger and go to the gallery folder

open themes

open carbon

open templates

edit navigatorMicroThumbs.tpl

on the end of the code after {/if} add the adsense code

I never try it on another theme

ps : I use adesnse 120 X 600

http://pho2o.net



Multi-ads

Here is another example how to add Google AdSense ads to matrix theme. I modified matrix theme and added one 200x200 ad to sidebar, one 728x90 banner and one 180x150 ad in the middle of 3x3 album/image display so that only 8 images are visible. All code and HOWTO is available here: http://wiki.version6.net/matrixad --Cougar 08:02, 28 May 2007 (PDT)

Matrix colors

To create your adsense code respecting the Matrix theme colors, use the following:

Border: FFFFFF Title: 6B8CB7 Background: FFFFFF Text: 000000 URL: EEEEEE

Related

How To Add Google Analytics to my Gallery 2

How to add ads between rows of thumbnails