Gallery2 AdSense: no module?
1st October 2006
If you ever need to add AdSense units to your Gallery2 installation, and find no module for this - try following the text below. I compiled it from several sources (primary menalto.com Gallery2 forum), and did everything written here myself here.
Primary source of information was this post, but I recommend that you follow instructions here.
To add AdSense to your Gallery2 sidebar (when using the Matrix theme as a sample):
- copy themes/matrix/templates/sidebar.tpl to theme/matrix/templates/local/sidebar.tpl on your server. This is needed to preserve your modifications when the Matrix theme will be upgraded.
- any further modifications should be done in your newly copied local/sidebar.tpl file.
- create the file which will contain all your AdSense code - e.g., let it be adsense_160x600.tpl for the Wide Scyscraper format. Put all your AdSense code into that file, and upload the file to your theme/matrix/templates/local/ folder on the server.
- now edit the sidebar.tpl file. My original file looked like this:
SMARTY:
I added
SMARTY:and final file looked like this:
SMARTY:-
{*
-
* $Revision: 1.2 $
-
* If you want to customize this file, do not edit it directly since future upgrades
-
* may overwrite it. Instead, copy it into a new directory called "local" and edit that
-
* version. Gallery will look for that file first and use it if it exists.
-
*}
-
<div id="gsSidebar" class="gcBorder1">
-
{* Show the sidebar blocks chosen for this theme *}
-
{g->block type=$block.0 params=$block.1 class="gbBlock"}
-
{g->block type="core.NavigationLinks" class="gbBlock"}
-
{* adsense code *}
-
</div>
-
- well, basically you are done. If you need/want to, you can wrap the inserted code into some styled container, to define the look of the block, like:
- you can use any AdSense format you like, but you must mind the width of the sidebar in your theme - so that site layout is not broken by too wide AdSense units.
Finally, some more hints and explanations.
The smarty variables for users in Gallery2 are:
- $user.isGuest
- $user.isRegisteredUser
- $user.isAdmin
As you might have noticed, in the code above AdSense unit is shown ONLY IF the page visitor is a Guest. Thus ads will not be shown to Registered Users and Admin. I did not manage to find this condition in Google's AdSense Policy, but the source post author states that showing Google Ads in password-protected areas is a violation of Google's Terms Of Service (TOS). Again - I did not find that, but in good faith I provide the code which limits ads to guest-only users. If you want to show ads to any user class - just remove the first {if} and last {/if} lines from the code. Any knowledgeable comments on this (preferrably with URLs) are very welcome, as personally I see nothing bad in putting AdSense onto password-protected pages in the case of the Gallery, where photos are the main type of content.
To add multiple ad units - create a single file for each distinct ad format/type you want to use, and include it using the code shown above. Just keep in mind limitations imposed by Google on the number of ad units of different types on a single page.
Hope this helps, and good luck to you.












October 1st, 2006 at 18:11
[...] Original post by Autarchy of the Private Cave. To read the full article visit: Autarchy of the Private Cave [...]
November 29th, 2006 at 1:35
[...] if you ever need to add adsense units to your gallery2 installation, and find no module for this - try following the text below. i compiled it from several sources (primary menalto.com gallery2 forum), and did everything written here …Read more: here [...]
November 30th, 2006 at 9:25
[...] Read more: here [...]