• This forum is for release discussion only. Discussions that do not relate specifically to the resource release should be discussed in another, more appropriate forum.
  • This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

Adding advertisements with template edits

Brogan

XenForo moderator
Staff member
Where are you adding that code? To which template?

You should be using the ad_ templates now.
 

Jesepi

Well-known member
Where are you adding that code? To which template?

You should be using the ad_ templates now.
Sorry for the delay in responding. That code is located in its own non-standard template, which is attached to the bottom of the 'message' template as


Code:
<xen:include template="adsense_firstpost_fakeuser" />
This is due to me wanting the advertisement to appear as a 'bot' posting that displays an ad after the first post in a thread. For example: http://tinyurl.com/c97mp4h
 

Stemis

Formerly Sasa
I want to add adsense only to index page, thread list page and show thread page. Which templates I need to edit?
 

mrGTB

Well-known member
If anyone can figure out how to get it to appear after the first post on every page (instead of just the first page), let me know.
ad_message_body (Template)

Code:
Code:
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND !in_array({$forum.node_id}, array(99,126,134)) AND !{$visitor.user_id}">
 
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
</xen:if>
You can exclude forums in the array you don't want ads displayed in, such as private hidden forums, news forums or whatever. And the ads are also only shown to guests. Ads get displayed in the first post on every page.
 

mrGTB

Well-known member
ad_thread_view_below_messages (Template)

Code:
<xen:if is="!in_array({$forum.node_id}, array(99,126,134)) AND !{$visitor.user_id}">
 
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
</xen:if>
You can show ads below messages, they are only shown to guests, and again you can exclude certain forums in the array from showing ads
 

JRW-910

Member
This has been a very valuable thread. After reading al lof it, I am still left with (hopefully) a simple question.

I want to display an ad to EVERYONE only on the main XenPorta and to GUESTS ONLY on the other pages.

Code:
<xen:if is="!{$visitor.user_id}" OR { ??? }>
   
ADSENSE
 
</xen:if>
I just can't figure out how to say... only on the main XenPorta page.

Any ideas?

Thanks,

-JRW

** Follow Up **

Thanks to Brogan, I figured out the code:

Code:
<xen:if is="!{$visitor.user_id} OR {$contentTemplate} == 'EWRporta_Portal'">
 
ADSENSE CODE
 
</xen:if>
 

Brogan

XenForo moderator
Staff member
I just can't figure out how to say... only on the main XenPorta page.

Any ideas?
How can I find out which template to edit?
Using your browser, view the page source and look for a line of code near the top of the page which begins
<div id="content" class="; the class is the name of the template. So for the main forum page, the line of code is:
<div id="content" class="forum_list">, which makes the template forum_list.

http://xenforo.com/community/threads/frequently-asked-questions.5183/#post-181112

The list of conditionals is here: http://xenforo.com/community/threads/frequently-asked-questions.5183/#post-182355

How can I show content on a specific page?
<xen:if is="{$contentTemplate} == 'xyz'">
This content will show on the xyz template
</xen:if>
 

Bram

Well-known member
I am still having problems with the usergroup permission settings. We have a few primary usergroups and 3 additional donator usergroups. The latter I don't want to bore with any ads on the forums.

Managed to hide or show ads for specific usergroups and it works flawless if they are only member of one usergroup. The problem starts with a user being a member of two usergroups. How do I solve that. Added example code below

Code:
<xen:hook name="ad_thread_view_below_messages" />
<xen:if is="{$visitor.user_group_id} == 1 OR {$visitor.user_group_id} == 2 OR {$visitor.user_group_id} == 4 OR {$visitor.user_group_id} == 6 OR {$visitor.user_group_id} == 9 OR {$visitor.user_group_id} == 10">
<div style="text-align: center">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-xxx";
/* RD Bottom Links */
google_ad_slot = "xxx";
google_ad_width = 728;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
</xen:if>
The usergroups that should not be affected by ads (primary or secondary) are 3,5,8,11,12,13
 

Brogan

XenForo moderator
Staff member
How can I hide content from more than one user group?
<xen:if is="!{xen:helper ismemberof, $visitor, x, y}">
This content will be hidden from members of user groups x or y
</xen:if>
 

Young

Member
Is anyone having an issue with this code?

While the ad shows up great, if you attempt to do an in-line edit on the first post of the thread.... when you click save the 'Save Changes'' button, the first post goes away until you refresh the page.
Same here :unsure:
 

Mutt

Well-known member
i thought I'd chime in. I placed an ad after the 1st post of every thread but if the 1st post was real short the ad would push into the post. I didn't like how it looked & fixed it. here's my code for ad_message_below w/ an explanation
  • the first if line is limiting this to threads (not PCs) and putting the ad after the 1st post of every page.
  • the <li> tag after that sticks a break after the post. (as if it's another post) This way the ad is never next to the avatar
  • the <div> after that is just some styling to put a box around the ad & is not necessary
  • the next if line is blocking the ad for anyone in the 9, 12, & 20 usergroups w/ a message that the ad was blocked.
  • after the else leaves all the other usergroups that do see ads. you could place your ad code there but I thru in another if. this if checks to see if we're in forum 6, the adult forum & makes sure NOT to display adsense there. it instead displays a adult ad.
  • after that else leaves all the non-adult forums & displays the adsense ad.
  • I'm not using after the next else but that would put code between all other posts & PCs I left it while I still plan out my ads in case I decide to put something there but probably won't.
Code:
<xen:hook name="ad_message_below" />
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND !{$message.conversation_id}">
    <xen:comment>after 1st post</xen:comment>
    </li><li id="after_1st_post_ad" class="message">
    <div align="center" style="background: white; padding: 10px; margin: 10px auto; border: 1px solid black; border-radius: 10px;">
        <xen:if is="{xen:helper ismemberof, $visitor, 20, 12, 9}">
            SFN Supporters & VIPs don't see this ad.
        <xen:else />
            <xen:if is="{$forum.node_id} == 6">
                adult ad code here
            <xen:else />
                adsense ad code here
            </xen:if>
        </xen:if>
    </div>
<xen:else />
    <xen:comment>between all other posts & PCs</xen:comment>
</xen:if>
with the default sex skin, here's the result. it's placed after the 1st post of page page of eery thread that is NOT in forum 6. most members see this.

Screenshot_3.jpg

the ones in groups that do not see ads, see this

Screenshot_5.jpg
 

Mutt

Well-known member
if you did not want to display anything to the people who don't see the ad, don't have an adult section, & have no need to ever put anything in the other places that ad_message_below covers, you could simplify it to

Code:
<xen:hook name="ad_message_below" />
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND !{$message.conversation_id} AND !{xen:helper ismemberof, $visitor, 20, 12, 9}">
    <div align="center" style="background: white; padding: 10px; margin: 10px auto; border: 1px solid black; border-radius: 10px;">
                adsense ad code here
    </div>
    </li>
</xen:if>
this would put an ad after the 1st post of every page of every thread for viewers not in groups 9, 12, or 20.
 

Mutt

Well-known member
How can I find out which template to edit?
Using your browser, view the page source and look for a line of code near the top of the page which begins
<div id="content" class="; the class is the name of the template. So for the main forum page, the line of code is:
<div id="content" class="forum_list">, which makes the template forum_list.

http://xenforo.com/community/threads/frequently-asked-questions.5183/#post-181112

The list of conditionals is here: http://xenforo.com/community/threads/frequently-asked-questions.5183/#post-182355

How can I show content on a specific page?
<xen:if is="{$contentTemplate} == 'xyz'">
This content will show on the xyz template
</xen:if>

I'm blocking ads for the albums but I have to block several templates. is there an easier / nicer way than what I'm doing?
Code:
<xen:if is="{$contentTemplate} != 'xfr_useralbums_member_albums_list_grig' AND {$contentTemplate} != 'xfr_useralbums_album_view' AND {$contentTemplate} != 'xfr_useralbums_albums_list_grid'">
would be nice if I could just prefix match the template
 

Mutt

Well-known member
I tired looking for variables used in the template like $album & $albums but my conditional wasn't seeing them. I finally settled on this. it was a little shorter / cleaner but most importantly it made adding more templates tot he mix easier.

Code:
<xen:if is="!in_array({$contentTemplate}, array('xfr_useralbums_add_images', 'xfr_useralbums_albums_list', 'xfr_useralbums_albums_list_grid', 'xfr_useralbums_album_view', 'xfr_useralbums_member_albums_list', 'xfr_useralbums_member_albums_list_grig', 'xfr_useralbums_add_images', 'xfr_useralbums_image_view'))">
 

Bram

Well-known member
I have ads displaying after every first post on all pages. However in private coversations the ads show after every post, is it possible to disable advertisements in private messages completely?
 
Top