Insert Google Adsense in Between Gallery Rows

Filed in: Adsense Tips, Make Money Online, Open Source, Web Development — March 4th, 2005

advertisement

Google Adsense in between Gallery rows
Google Adsense in between Gallery rows

I use Gallery for my gallery page, with Google Adsense ads. By Integrate Gallery into Wordpress, I am able to add Adsense code at page header and/or footer.

But, since my album is displayed in 3 rows, I think putting Adsense ads in between Gallery rows will better increase the appearance and click rate(hopefully :wink: ).

Problem
I search through Internet but failed to find helpful resources. The "html_wrap" files only support for Header, Footer, and Frame. Doesn't has html wrap for Gallery Rows.

At the end, I solved it by myself with dirty trick. Read on for details.

Solution
Since html_wrap does not help this time. I modified the "view_album.php" file to get my ads display in between rows. "view_album.php" is the PHP file to display photo albums in Gallery.

Warning! Editing "view_album.php" is NOT recommended. Make sure you have backup the file first before modify it. Backup!

Insert Google Adsense Code In Between Gallery Rows

  1. Backup "view_album.php" file!
  2. Open "view_album.php" for editing.
  3. Search for the following lines of code:
    PHP:
    1. if ($printTableRow) {
    2.    echo('</tr>');         
    3.    }
    4.    $rowCount++;
    5.    $rowStart = $visibleItemIndex;

  4. Insert your Google Adsense code AFTER:
    PHP:
    1. if ($printTableRow) {
    2.    echo('</tr>');

    and, BEFORE :

    PHP:
    1. }
    2.    $rowCount++;
    3.    $rowStart = $visibleItemIndex;

  5. If you are doing it right, it will looks something like this:
    PHP:
    1. if ($printTableRow) {
    2.    echo('</tr>');      
    3.    // START - Insert adsense in between Gallery row
    4.    ?>      
    5.    <tr align="center"><td colspan='<?php echo $cols ?>'>
    6.    <!-- START ADSENSE CODE -->
    7.    <script type="text/javascript"><!--
    8.    google_ad_client = "pub-6483020658630886";
    9.    google_ad_width = 468;
    10.    google_ad_height = 60;
    11.    google_ad_format = "468x60_as";
    12.    google_ad_channel ="6226672817";
    13.    google_color_border = "0066CC";
    14.    google_color_bg = "FFFFFF";
    15.    google_color_link = "000000";
    16.    google_color_url = "666666";
    17.    google_color_text = "333333";
    18.    //--></script>
    19.    <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    20.    </script>
    21.    <!-- END ADSENSE CODE -->
    22.    </td></tr>
    23.    <?php // END - Insert adsense in between Gallery row
    24.    }
    25.    $rowCount++;
    26.    $rowStart = $visibleItemIndex;

  6. Save the modified "view_album.php" file and upload back to your Gallery folder. Backup the file before replace!
  7. Done!

Note: The sample Adsense code is mine. If you use it in your Gallery, I am the one who get the money! It is highly recommended! :razz:

Thought:
Actually, this trick is quite simple but editing Gallery PHP file is never be recommended. If you want to modify it, please do backup.

Bookmark and Share

Read also:

blog comments powered by Disqus