Skip to main content
Home
The Baheyeldin Dynasty
The journey for wisdom starts with knowledge
  • Home
  • About
  • Site Map
  • Contact

Using Drupal 4.7 regions to show/hide AdSense

  1. Home
  2. Resources for using Google Adsense with Drupal

By Khalid on 2005/10/08 - 13:09, last updated 2005/10/08 - 13:44

In a previous article, I described how one would use flexinode to display ads anywhere on the page, and not just blocks. This can be used to achieve things like restricting ads from showing on certain pages.

This can be achieved using Drupal 4.7 regions feature, which, like flexinode, allows multiple regions for blocks to be placed in. The default regions are left sidebar, right sidebar, header, footer and content.

However, blocks are always displayed with their title, which is ugly anywhere apart from the sidebars. Although CSS can be used to hide the header, this is more of a hack than the proper way of doing things.

Initial Attempts

Initially, I tried the following code in page.tpl.php:

<?php
$block = block_block('view', 1); // Block 1
drupal_set_content('content', $block['content']);
?>

The problem is that it will not obey the visibility rules of the block. Even if the block is disabled, it will still show in the following code. If it is to be shown only on non-admin pages, this rule will be ignored, and it will show everywhere. Not exactly what I wanted it to do.

The Proper Way

After corresponding with Nedjo Rogers, the author of 4.7's regions feature, and a lot of experimentation, here is the solution that can be used. This assumes that you have a PHPTemplate based theme.

Change the theme's block.tpl.php so that it looks like so:

<?php
switch($block->region) {
case 'ad_top':
case 'ad_bottom': ?>
<div class="<?php print $block->region; ?>"><?php print $block->content; ?></div>
<?php
break;
default: ?>
<div class="block block-<?php print $block->module;?>"
id="block-<?php print $block->module;?>-<?php print $block->delta;?>">
<h2 class="title"><?php print $block->subject; ?></h2>
<div class="content"><?php print $block->content; ?></div>
</div>
<?php
break;
} ?> 

Notice that for the ad_top and ad_bottom regions, only the block's content is displayed, and the region is used as the div's class.

Create a template.php or edit it, and add the following function to it:

<?php
function bluemarine_regions() {
return array(
'ad_top' => t('ad top'),
'ad_bottom' => t('ad bottom')
);
} 

This defines two new regions for your theme, ad top and ad bottom. You can add as many regions as you want.

Create new blocks, put in them the call to the adsense_display() function with the arguments you want, and assign them to the regions you created.

Now, you can use simple statements to display the ads in your page.tpl.php or node.tpl.php anywhere you want, for example:

<?php print $ad_top; ?>
<?php print $ad_bottom; ?> 

Although the technique I mentioned uses Adsense as an example, it can be used to display anything. For example, you can use code snippets from the Drupal web site and display them anywhere you want.

Contents: 
Drupal

Book Navigation

  • ‹ Links and Resources on Google Adsense
  • up
  • Using Google AdSense with Drupal ›
  • Add comment

Comments

Ata Allah (not verified)

Drupal 4.7

Wed, 2005/11/09 - 02:12

Greetings,

How to obtain Drupal 4.7 ?
At the site, tha latest version is 4.6.3

Regards,
Ata

  • reply

Khalid

Not released yet

Tue, 2005/11/15 - 21:42

It is not released yet.

You can experiment with the CVS version, which is still under development.
--
Khalid Baheyeldin

  • reply

Budda (not verified)

Block titles not needed

Wed, 2006/02/08 - 05:58

Block titles are not required in Drupal 4.7

So in the block.tpl.php simply do a if($block->subject) around the printing of the block title.

If no title is defined, nothing gets printed to the page. Works a treat!

  • reply

aoc gold (not verified)

Is this still the case or is

Fri, 2008/08/08 - 12:15

Is this still the case or is there a more recent work around?

  • reply

m3avrck (not verified)

Overriding regions example has one caveat...

Sun, 2006/02/19 - 13:25

Hi Khalid, there seems to be one slight problem with defining regions as bluemarine_regions() ...

If you do that, your site *only* has 2 regions now, and the default left, right, content, header, and footer are gone!

What should happen is you should copy the entire phptemplate_regions() and then append your regions, otherwise you can get some funky results.

Great article though!

  • reply

G.M. Nowels (not verified)

block.tpl.php code loses regions

Mon, 2006/05/15 - 17:20

When I add your block.tpl.php change to my theme I loose my footer and footer region.

  • reply

Khalid

Define them all

Mon, 2006/05/15 - 17:50

Define all the regions, not just the new ones.

This way, you do not lose any of them.

  • reply

Qrios (not verified)

Adding to regions array in Drupal

Tue, 2006/12/05 - 08:50

This works for me:

<?phpfunction theme_regions() {$arr_regions = phptemplate_regions();$arr_regions['extra_region'] = 'extra region';  return $arr_regions;}?>

Regards

  • reply

Dizwell (not verified)

Non-privileged users can set Adsense IDs

Thu, 2006/10/26 - 01:44

First of all, thank you for a very nice module that behaves admirably. Second, I am sorry if this is not the right place to ask a question, and if there is a better place please let me know.

My issue is that, after having installed the Adsense module, and specifically after having made the Profile a 'private field, content only available to privileged users', ordinary, non-privileged users can see a tab that lets them access the Adsense Client ID field whenever they edit their profile. When they do so, they get a message to the effect that "the content of this field is kept private" -but they can nevertheless enter a value there, and click 'Submit'.

Checking with the contents of the PROFILE_VALUES table in MySQL, the 'submit' button really does add an entry into that table.

So my questions really are: (1) should all non-privileged users be able to even see the Adsense tab in their profiles? If not, what do I do to fix the privilege issue? (2) if they make an entry there and end up adding rows to the PROFILE_VALUES table, does that affect *my* adsense configuration and revenue-raising capabilties?

If it turns out the answers are (1) it doesn't matter if they can see the option, so long as they can't edit your entry and (2) so long as your entry is fine, your adsense revenues will be unaffected, I'd still like to request some mechanism for hiding the adsense field from users completely.

But I imagine it's my fault it's visible at all, and I would very much like to know what I've done wrong!

Regards
HJR

  • reply

Khalid

Private means for others to view

Thu, 2006/10/26 - 10:28

Private here means that others would not be able to view the field value.

Anyone can enter a value though.

So this behaviour is expected.
--
Khalid Baheyeldin

  • reply

Pages

  • 1
  • 2
  • next ›
  • last »

Current

Pandemic

  • COVID-19
  • Coronavirus

Search

Site map

Contents

  • Family
    • Khalid
    • Ancestry
    • Extended
  • Friends
  • Nokat نكت
  • Writings
    • Cooking
    • Culture
    • Science
    • History
    • Linguistics
    • Media
    • Literature
    • Politics
    • Humor
    • Terrorism
    • Business
    • Philosophy
    • Religion
    • Children
  • Technology
    • Linux
    • Arabization
    • Drupal
      • Association
    • Software
    • Internet
    • Technology in Society
    • Digital Archeology
    • NCR History
    • MidEast Internet
    • Programming
    • Saudi ISPs
    • Miscellaneous
  • Places
    • Canada
      • Weather
    • Egypt
      • Cuisine
      • Alexandria
      • E.G.C.
    • USA
    • Saudi Arabia
  • Interests
    • Astronomy
    • Fishing
    • Photography
    • Snorkeling
    • Nature
    • Photomicroscopy
  • Miscellany

In Depth

  • al-Hakim bi Amr Allah: Fatimid Caliph of Egypt الحاكم بأمر الله
  • Alexandria, Egypt
  • Arabic on the Internet
  • Articles on the history of Muslims and Arabs in the Iberian Peninsula تاريخ المسلمين و العرب في الأند
  • DIY GOTO Telescope Controller With Autoguiding and Periodic Error Correction
  • E.G.C. English Girls College in Alexandria, Egypt
  • Egyptian Cuisine, Food and Recipes مأكولات مصرية
  • George Saliba: Seeking the Origins of Modern Science?
  • Internet Scams and Fraud
  • Mistaken for an Arab or Muslim: Absurdities of being a victim in the War on Terror
  • Mistaken Identity: How some people confuse my site for others
  • One People's Terrorist Is Another People's Freedom Fighter
  • Overview of Google's Technologies
  • Photomicroscopy
  • Pseudoscience: Lots of it around ...
  • Resources for using Google Adsense with Drupal
    • Drupal Module: Google AdSense
    • Drupal: Using flexiblock to show/hide AdSense
    • Links and Resources on Google Adsense
    • Using Drupal 4.7 regions to show/hide AdSense
    • Using Google AdSense with Drupal
    • Drupal AdSense Module: Added Section Targeting
    • How To Include Drupal Comments In Section Targeting
  • Rockwood Conservation Area, Southern Ontario
  • Selected Symbolic Novels And Movies
  • Snorkeling the Red Sea near Jeddah
  • Updates and Thoughts on the Egyptian Revolution of 2011

Recent Content

Most recent articles on the site.

  • Origin Of COVID-19: Natural Spillover, Lab Leak Or Biological Weapon?
  • Kamal Salibi and the "Israel from Yemen" theory
  • How To Upgrade HomeAssistant Core In A Python Venv Using uv
  • Ancestry - Paternal Side
  • Review of Wait Water Saver For Whole House Humidifiers
more

Most Comments

Most commented on articles ...

  • Another scam via Craigslist: offering more than asking price
  • Warning to female tourists thinking of marrying Egyptians
  • Craigslist classified for used car: Cheque fraud scam
  • Winning the lottery scam email: World Cup South African lottery
  • Email Scam: BMW 5 Series car and lottery winning
more

About Khalid

Various little bits of information ...

  • Khalid Baheyeldin: brief biography
  • Presentations and Talks
  • Youtube Videos
  • GitHub Projects
  • Drupal.org Profile
  • Astrophotography @ Flickr

Sponsored Links

Your Link Ad Here

Tags

Android Mobile Ubuntu Sony OnStep OpenWRT Router Ericsson COVID-19 Rogers Coronavirus Arabic Kubuntu Home Assistant GSM Telescope tablet Spectrum Scam Python 419 Laptop Firefox DIY CPU Conspiracy Comet Balkanization backup App
More

© Copyright 1999-2025 The Baheyeldin Dynasty. All rights reserved.
You can use our content under the Terms of Use.
Please read our privacy policy before you post any information on this site.
All posted articles and comments are copyright by their owner, and reflect their own views and opinions, which may not necessarily be consistent with the views and opinions of the owners of The Baheyeldin Dynasty.

Web site developed by 2bits.com Inc.