• Skip to main content
  • Skip to primary sidebar

xfpoint

XenForo Resource Site with Tips, Tricks and Hacks

  • Home
  • About
  • Glossary
  • Guides
  • Tutorials
  • Add-ons
  • Contact
You are here: Home / Tutorials / How to Show Ads Only In The First Post Of XenForo 2

How to Show Ads Only In The First Post Of XenForo 2

October 29, 2017 by Shabbir Bhimani

Adding advertisements in XenForo 2 is a cakewalk. XenForo 2 has many ad locations within the layout and well organized in the admincp. Visit XenForo admincp > Setup > Advertising and click the Add advertisement button in the top right corner.

Choose a Title for the ad, it is only for reference in the admin area and not visible to the user. Select Post: Above message content or Post: Below message content as position, and in the HTML box add your ad code.

The ad code will repeat in each post for post_above_content and post_below_content and one needs to add the following conditional in the HTML to restrict the ads to be shown only in the first post

<xf:if is="$post->position == 0">
YOUR AD CODE HERE
</xf:if>

If you wish to show ads in the second post change the position conditional to 1.

<xf:if is="$post->position == 1">
YOUR AD CODE HERE
</xf:if>

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on WhatsApp (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)

Filed Under: Tutorials Tagged With: Ad Location, Ads, XenForo Conditional

About Shabbir Bhimani

xfpoint.com is an independent XenForo resource site with tips, tricks, hacks, and resources for new XenForo webmasters to improve their community. Read More…

Primary Sidebar

About Shabbir Bhimani

xfpoint.com is an independent XenForo resource site with tips, tricks, hacks, and resources for new XenForo webmasters to improve their community. Read More…

© xfpoint 2025. xfpoint.com is an independent XenForo resource site for new xenForo webmasters.

Copyrighted code samples of XenForo will be visible only if you have a valid xenForo license.