News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Prevent a DIV block from showing on certain topic or page

Started by Imakarum, April 16, 2014, 02:17:53 PM

Previous topic - Next topic

Imakarum

Hi! How can I prevent a DIV block from showing on the certain topic or page of my forum?

I want to install Adsense in those blocks, but I don't want them to show up on certain pages/topics (like pages with embedded videos, pages with bad words or other pages, which can be considered by Google as bad for displaying Adsense).

Now I'm using the code like this in Display.template.php to show blocks only for guests and only after the first post in the topics:

if ($message['id'] == $context['first_message'] && $context['user']['is_guest'])

{echo '<div>Ads are here</div>';}


Can I modify it somehow, so ads will not show up on some of my pages/topics? Maybe I can add topic ID or page urls in this code?
Maybe adding something like this:
&& $topic id['123'] && $topic id['124'] where 123 and 124 are IDs of topics (sorry, I'm a total noob in PHP).


As an alternative I'd like to set some kind of word filter, which will prevent a block with ads from showing on the pages with those words (or with embedded video code).  I know there is a "Censor Adsense on Bad Words" mod, but it's compatible only with SMF 2.0. Maybe there is a way to get it working on my 1.1.x?

margarett

The firs part if your question is addressed with in_array
You build an array of excluded (or included) topics to show and use in_array to find out if the current topic in in the array you specified. Or else you might end up with a zillion combinations in your "if"

For the second part, that would require some more extensive work... The page content is parsed "on the fly". That means that only after each message is there already, then you know what to display. In your case, having such evaluation before showing the messages in order to decide whether or not to show the ad... Dunno, honestly...
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Kindred

Why not just use one of the portals or ad manager mods?  You can control those blocks...  Although I don't know if you can do it down to the individual post level...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Imakarum

Thanks for replies!

margarett I like your suggestion about in_array and I want to make it work :) I went to Google for info about arrays and that's how far I've moved on:

Do I need to add something like this?

$Array_Name = array(1, 2, 3, 4);

if ($message['id'] == $context['first_message'] && $context['user']['is_guest'] && (!in_array($Array_Name)))

{echo '<div>Ads are here</div>';}


I wrote 1, 2, 3, 4 on the place where I imagine excluded topics IDs. How can I add topics IDs in the array?

margarett

in_array takes 2 arguments
http://www.php.net/manual/en/function.in-array.php

So your last part needs to be
!in_array($context['current_topic'], $Array_Name)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Imakarum

Thank you margarett! Works fine :laugh:

---
At first I was confused - I was thinking what should I put here instead of my example numbers:
$Array_Name = array(1, 2, 3, 4);

But it's looks like I just need to put topics IDs here lol

Advertisement: