Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
coding-topic
Adsense code
Avatar
tyleryoungblood
Seattle, WA
Member
Free Members
sp_UserOfflineSmall Offline
Oct 6, 2012 - 5:19 pm

Awesome! Thanks for the help everyone!

By the way, if you want to display your Adsense ads in multiplie locations, like say on the 1st and 5th post in a topic, you can modify your function code as follows:

if($spTopicView->currentPost==1 OR $spTopicView->currentPost==5){ //display if 1st or 5th post
     if (function_exists('show_ad')) show_ad();
}

Keep in mind that Adsense only allows 3 ads per page. So maybe you could modify even further for 1st, 5th, and 10th post. Or you could create separate functions for 3 different ad sizes and place them in 3 distinct locations (header, post1, and footer).

Thanks again for this post. It helped me find the right locations to place my ad code!

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Oct 6, 2012 - 5:33 pm

yup... the sp template files are simply php... you can do whatever kind of special logic you want... if you get in pretty heavy, dont forget about the data inspector on forum - toolbox - data inspector... will help with available data...

Avatar
jamie771
Member
Free Members
sp_UserOfflineSmall Offline
May 26, 2013 - 2:12 pm

How do I find: spFunctions and spTopicView.php. In which folders are they? Thanks

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
May 26, 2013 - 2:50 pm

to learn about the basics of themes, see:  http://codex.simple-press.com/.....ng-themes/

Avatar
Myriam HERVE
Member
Free Members
sp_UserOfflineSmall Offline
Sep 4, 2013 - 8:53 am

Hello ! Just a little message to say "thank you", because the information provided by Brandon C on page 3 are very clear and useful ! 

I've just set up adsense on my forum in a few minuts !

And if you want to display the banners every 5 posts, just use this code : 

if ($spTopicView->currentPost % 5 == 0) {
 if (function_exists('show_ad')) show_ad();
 }
Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Sep 4, 2013 - 9:26 am

Glad it helped you. Nice and simple use of the remainder operator there...

andy-signature.png
YELLOW
SWORDFISH
Avatar
almase
Member
Free Members
sp_UserOfflineSmall Offline
Sep 11, 2013 - 4:52 pm

Myriam HERVE said
Hello ! Just a little message to say "thank you", because the information provided by Brandon C on page 3 are very clear and useful ! 

I've just set up adsense on my forum in a few minuts !

And if you want to display the banners every 5 posts, just use this code : 

<br />

if ($spTopicView->currentPost % 5 == 0) {
 if (function_exists('show_ad')) show_ad();
 }

<br />

What do I have to change if the code should appear always in the last post?

Or maybe the first and the last post?

THX

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Sep 11, 2013 - 10:05 pm

try

if ($spTopicView->last_post_on_page)

or

if ($spThisPost->first_post_on_page || $spThisPost->last_post_on_page)

you should take a look at forum - toolbox - data inspector... great way to look at the info available on page views...

Avatar
dom to
Rookie
Free Members
sp_UserOfflineSmall Offline
Jun 15, 2014 - 10:46 pm

Mr Papa said

just change your checks on the current post position...

<br />

if ($spTopicView->currentPost == 1 || $spTopicView->currentPost == 3 || $spTopicView->currentPost == 4)

<br />

or break it up into separate 'if' statements...

Thanks for that, it's work good, i try this code before:

if

(
$spTopicView->currentPost==1) || ($spTopicView->currentPost==4){

echo

'my ad code here';

}
 
 
But it's don't work.

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Jun 16, 2014 - 12:35 am

the code you entered is not syntactically correct and has php errors in it...  you probably want something like this:

if ($spTopicView->currentPost==1 || $spTopicView->currentPost==4) {
    echo 'my ad code here';
}

but I am not sure what you want, so try it and see if it gives you what you want with your php error fixed... come on back if not what you want...

Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 620
Members: 17365
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10128
Posts: 79626