Check for ad

Posted in: Newspaper
Post count: 388

I’m modifying my header template to move the ad around. I’ve got it working. But I want to make my logo return to its normal (centred) place if there’s no ad currently displaying. So I assume I can put a conditional around the ad div in my php.

My question is: what is the condition? I’m reading the line

echo td_global_blocks::get_instance('td_ad_box')->render(array('spot_id' => 'header'));

and wondering is there something like

if (!empty(td_global_blocks::get_instance('td_ad_box')))...

?

Post count: 6600

Hi,

You could try to structure your condition something like this:

if (!empty(td_global_blocks::get_instance('td_ad_box'))) {
echo td_global_blocks::get_instance('td_ad_box')->render(array('spot_id' => 'header'));
}
else {
place here the code for the header without the ad
}

If you don’t know how to do this I recommend you to hire a developer to do it for you.
Hope this helps!

Thanks

  • This reply was modified 11 years by Lucian.
  • This reply was modified 11 years by Lucian.
Post count: 388

Thanks. That’s what I tried at first, but it looks like the condition is never triggered because the output isn’t so straightforward. (I realized that the condition doesn’t even specify the header, so it wouldn’t pull the right ad box anyway.)

A var_dump of

td_global_blocks::get_instance('td_ad_box'))

yields

object(td_ad_box)#1657 (2) { ["block_id"]=> string(9) "td_ad_box" ["block_uid"]=> NULL }

whether there’s content in the header ad space or not.

In the end the condition had to be

if (td_global_blocks::get_instance('td_ad_box')->render(array('spot_id' => 'header')))

and I was wrong about using empty because what that returns is not a variable.

Thanks for the help! Hope someone else benefits from this thread.

Post count: 6600

Hi,

Glad you figured it out!
Thanks for sharing!

Viewing 4 posts - 1 through 4 (of 4 total)
The forum ‘Newspaper’ is closed to new topics and replies.