PDA

View Full Version : How to set style depending on location on site?


RobParker
04-12-2007, 09:29 AM
Hi all,

Hopefully this is possible and simple as it's really important that we manage to get this done.

We have a VB site running vbadvanced as the homepage/news section and then linking to our forums.

We have the header and footer templates modified to put the right hand column down the side of the entire site on every page and use this column for our adverts. The code for the ads themselves are linked through a plugin we've set.

The code looks like this:


<!-- Right Column Code -->
</td>
<td width="120" valign="top" align="left">$advertcode</td>
</tr>
</table>
</td></tr>
</table>
<!-- End Left Column Code -->

The plugin is then:


ob_start();
include('urls/to/site/forums/adverts.php');
$advertcode= ob_get_contents();
ob_end_clean();


And the adverts.php file contains the html/javascript for our adverts.

The problem we have now is that we need to differentiate between our forums pages and our other pages and display different advertising code depending on the two.

What we basically need to do and what I hope is possible is that we can do the following:


<!-- Right Column Code -->
</td>
<td width="120" valign="top" align="left">

IF location = forums ($advertcode)
ELSE ($newadvertcode)

</td>
</tr>
</table>
</td></tr>
</table>
<!-- End Left Column Code -->

And add in some kind of if statement to set the code to a different plugin to display different ads depending on whether you're on the forums or not.

Is this possible at all? It's quite urgent as we've just been informed that we need to make this change ASAP.

Cheers for any help.

Rob

Lynne
04-12-2007, 02:48 PM
At the top of your forumsdisplay.php file, it has something like this:
define('THIS_SCRIPT', 'forumdisplay');

So I think you can use that variable, THIS_SCRIPT, to do your if statement.

<if condition="THIS_SCRIPT == 'forumdisplay'">
$advertcode
<else />
$newadvertcode
</if>

RobParker
04-12-2007, 03:03 PM
Superb.

That doesn't quite do what I need but is certainly along the right lines.

forumdisplay, showthread, newreply etc would all need to be included in the condition but something like

THIS_SCRIPT == '(forumdisplay' OR 'showthread' OR etc etc)

should work.

I think I'm right in saying it's also possible to do it by forumid so I could display just certain ads in our "news" forums but not in the others, right?

Ideally what I'd have is:

Front page/vbadvanced modules

Forum pages relating to forums 1 and 2.

Forum pages relating to forums id 3-10 (for example)

I think with a nested IF statement then I can both select the scripts as well as the forum ids.

If anyone is able to post what code they should I should be using it'd be great but I think I can figure it out now.

Thanks again.

Lynne
04-12-2007, 07:09 PM
I think this is kinda what you want, but I don't know what the THIS_SCRIPT display is for vbadvanced (I don't have it on my site):

<if condition="THIS_SCRIPT == 'forumdisplay' OR THIS_SCRIPT == 'vbadvanced'">
$advertcode
</if>
<if condition="in_array($foruminfo[forumid], array(1,2))"/>
$newadvertcode
</if>
<if condition="in_array($foruminfo[forumid], array(3,4,5,6,7,8,9,10))"/>
$anotheradvertcode
</if>

That's assuming there is no overlap in forumdisplay/vbadvanced and any of the forumids, or else you would nest the foruminfo conditional with the other depending on which one takes precedence.

(This isn't tested and I'm no expert, so some tweaking may be necessary. ;) )

RobParker
04-12-2007, 07:45 PM
Thanks Lynne.

That's not quite what I need as there has to be an else statement in there(I don't think I explained myself as well as I could have done) but at least I understand what I need to do now.

The THIS_SCRIPT for VBA is adv_index for the homepage by the way. Once I've tested it out I'll post what I ended up using.

Lynne
04-14-2007, 02:56 AM
Well, you probably want the else before the forum part, something like:
<if condition="THIS_SCRIPT == 'forumdisplay' OR THIS_SCRIPT == 'adv_index'">
$advertcode
<else />
<if condition="in_array($foruminfo[forumid], array(1,2))"/>
$newadvertcode
</if>
<if condition="in_array($foruminfo[forumid], array(3,4,5,6,7,8,9,10))"/>
$anotheradvertcode
</if>
</if>

You know better than I what the exact conditional would be for your forums, so just tweak it until it reads right for you.

RobParker
04-18-2007, 01:25 PM
Quick question on syntax.

Why do you close off you're if statements after the first one?

For example the closing / here:


<if condition="in_array($foruminfo[forumid], array(1,2))"/>