Announcement

Collapse
No announcement yet.

Help Adding Conditional Area To Header In Relation To Templates?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help Adding Conditional Area To Header In Relation To Templates?

    Hi, I'm a bit of newb to vB and not a coder of any sort (other than the odd basic hack) - I want to add some custom code to the overall header of the site. Basically, when the header appears on forum pages with content (index, forum and thread) I want one piece of code. When its an admin or non-content page like Private Messages, other code is displayed.

    Can I do it by template? So for instance, if the page is displaying any of these templages it will give me one lot of code:

    SHOWTHREAD
    FORUMHOME
    FORUMDISPLAY

    And when anything else is being shown it gives me the other code. I don't know the syntax to achieve this beyond the basic - can anyone help me or confirm if my thinking it doing this is efficent and correct.

    Code:
    <if condition="*SHOWTHREAD - FORUMHOME - 
    FORUMDISPLAY Templates in use*">
    
    Custom HTML For main content pages
    
    <else />
    
    Custom HTML for all other pages
    
    </if>
    Also - are those the three I need for achieving my aim - I've just converted from PHPBB where I did this by directly editing the themes .tpl files which were: index_body.tpl, viewforum_body.tpl and viewtopic_body.tpl.

    And if you guessing, this is to stay within the AdSense TOS


  • #2
    If you are looking to show ads from AdSense only on specific pages, you simply need to make use of the THIS_SCRIPT variable that is set within each PHP file.

    For example, THIS_SCRIPT in index.php is defined as index. So that is how you would use a condition to compare the pages.

    So if you want to limit the showing of the ads to just the forumhome (i.e. index.php), then you would use:

    Code:
    <if condition="THIS_SCRIPT == index">
    
    AdSense Code Here
    
    <else />
    
    &nbsp;
    
    </if>
    Now, you can extend this to work with other pages as well, it is just a matter of pulling the THIS_SCRIPT variable from the PHP file in question.

    So to pull of what you are looking to do with the 3 above areas, you simply need to use:

    Code:
    <if condition="THIS_SCRIPT == index OR THIS_SCRIPT == forumdisplay OR THIS_SCRIPT == showthread">
     
     AdSense Code Here
     
     <else />
     
     &nbsp;
     
     </if>
    Hope that helps a bit.

    Comment


    • #3
      Originally posted by KingSpade
      Hope that helps a bit.
      If by helps a bit you actually means solves the problem in one fell swoop, then yes, that helped a bit.

      Many thanks, if I could rep you, I would.

      Comment


      • #4
        heh, no problem , glad it helped

        Comment


        • #5
          using this code how do i limit ads to a few forums? like if i want forum 1, 2 and 3 to show ads how should that code look? thanks for the help.

          <if condition="THIS_SCRIPT == index OR THIS_SCRIPT == forumdisplay OR THIS_SCRIPT == showthread">

          AdSense Code Here

          <else />

          &nbsp;

          </if>

          Comment

          widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
          Working...
          X