Support Forum

Adsense code

AU ausip
ausip
Member

I read in the features that hooks are now obsolete…

 

If that is the case, where do I find the information to include adsense code in my forum templates?

39 Answers

New Answer

YS Yellow Swordfish
Yellow Swordfish
Member

mainly still in the process of being written.
But there are many options. probably best at the moment if you tell us where you want to put it and we can advise on the best approach…

AU ausip
ausip
Member

The main place I would like to put advertising to begin with would be after the first post on the topic page.

 

Thanks

MP Mr Papa
Mr Papa
Member

you can just stick it in the template file for the sp theme you are using, checking for $spTopicView->current_post==1, after the inner post loop…

right after these

                        sp_InsertBreak();

                    sp_SectionEnd(”, ‘post’);

just use the php echo statement to output the adsense code… you might want to style it…

as always, we recommend you make your own sp theme before editing ours to prevent losing changes on upgrade… http://codex.simple-press.com/codex/themes/theme-basics/creating-a-theme/

AU ausip
ausip
Member

Thanks for that. There are a couple of other locations that I need to know about too.

I am using the Social Connect plugin and want to include it’s code in the login for Simple:Press. What is the location in the code to include it between the password and Login button, after clicking on Login to display these fields.

 

I also want to include some social networking buttons on each topic. This would need to go at the bottom of each topic post and reply.

 

I look forward to your reply, so I can start inserting some code in a custom template.

Thanks

Paul

YS Yellow Swordfish
Yellow Swordfish
Member

If you take a look at the template files and compare them to the display of the forum it really is pretty easy to work out the structure. Each display element simply has it’s own function and you can add standard php and html code anywhere you like. Just echo the output.

UN
Unknown
Member

I’m really new at this whole PHP thing… what is meant by an echo?

For example, I want to place a 728×90 Adsense ad below the first post of the forum, and under it (before the forum information section). I see the locations as to where to put it, from previous forum posts as well as this one, but I’m not familiar with how to “echo” it. I was placing the code there, and it was returning errors on the page.

 

Any help would be appreciated. A template of it would be so amazing, but It’s not “expected” or anything. Thank you! 

BR Brandon
Brandon
Member

Here is how you can do it.

First create your own theme so any changes you make are not over written by updates. See here on how.

http://codex.simple-press.com/codex/themes/theme-basics/creating-a-theme/

Since you want to use the adsense code in multiple paces I would create a function for it.

It appears you have seen the files in yourthemes/template folder.  One of the is spFunctions.php.  This is a file that you can add a function to, among other things, that your theme can use.

Create a function for your ad. Let’s call it spAddCode

Open the spFuntions.php file up in your editor and at the bottom just above the closing ?> is where you can add the function.

Your function should look something like this.

function spAddCode() {
spAddCode();

Then if you ever want to change all your ads you can edit the adsense code in one file and it will be changed for every place your have spAddCode()

From there you could actually create multiple functions for various size ads. IE; spAddCodeBigBanner() or spAddCodeSmallBanner(), etc.

As a side note, Adsense code does not contain any formating left/right/center etc. Most people just want them centered. If so you can use.

echo ‘<center> all your google adsense code goes here </center> ‘;

JG Jasneet Gulati
Jasneet Gulati
Member

Hi,

Thanks for the above information.

I have successfully implemented Adsense in the spHead.php

I now also want an add below the very first post of any topic. I know the code I need to place, but I am looking everywhere for:

Mr Papa said
 checking for $spTopicView->current_post==1, after the inner post loop…

right after these

                        sp_InsertBreak();

                    sp_SectionEnd(”, ‘post’);

In which .php file will I find this bit of code so that I can echo my adsense code? I have checked spTopicView.php as well as several others.

Thank you,

JG

YS Yellow Swordfish
Yellow Swordfish
Member

It IS spTopicView.php. You will find the bit Steve suggested in there.

JG Jasneet Gulati
Jasneet Gulati
Member

Yellow Swordfish said
It IS spTopicView.php. You will find the bit Steve suggested in there.

Yes you are right, my apologies.

When I opened it previously it was in notepad. When I opened it in Dreamweaver I found it..mostly.

In my spTopicView.php I found the following:

“sp_InsertBreak();

                    sp_SectionEnd(”, ‘post’);”

and I inserted my echo after this – it worked to some extent. It shows below the first 3 or 4 posts. Not after the first post only.

I could not find this code:

“$spTopicView->current_post==1”

So I’m almost there.

Did you want me to include this bit of code myself?

Thank you Yellow Swordfish – I’m sorry about using Notepad to find the code before, I have learnt from this.

YS Yellow Swordfish
Yellow Swordfish
Member

You need to code that bit yourself. As in:

if ( $spTopicView->current_post == 1 ) {
    .. do your stuff
}

Adding your adsense code within the if test.

JG Jasneet Gulati
Jasneet Gulati
Member

You’re so fast mate! Thank you!

I’m afraid I could not get it to work.

This is what I have – where am I going wrong?:

sp_PostIndexUserSignature(‘tagClass=spPostUserSignature spCenter&maxHeightBottom=55’);
sp_InsertBreak();

sp_ColumnEnd();

sp_InsertBreak();

sp_SectionEnd(”, ‘post’);

if ( $spTopicView->current_post == 1 ) {

echo show_ad_camp_3();

}

endwhile; else:
sp_NoPostsInTopicMessage(‘tagClass=spMessage’, __sp(‘There are no posts in this topic’));
endif;

YS Yellow Swordfish
Yellow Swordfish
Member

I’m sorry – I should have looked a little harder at Steve’s coding suggestion.

That should be: $spTopicView->currentPost

Note – no space and the capital P.

JG Jasneet Gulati
Jasneet Gulati
Member

SUCCESS!

Thank you very much. What a great service.

I hope you have a great weekend and an even better life, good sir.