• Resolved andyspeed

    (@andyspeed)


    Hi all. I wonder if anyone has an intuitive solution to my problem. I have two themes for my site – one is white, and the other is black. I placed my Ads in php files that are included where necessary.

    The adverts are white.

    However, when a user switches theme to the black one, the ads obviously stay white.

    Is there a way I can call one php file (containing one style of ad) if a certain template is used, and call another php file containing the other ad style when the other template is used?

    Andy

Viewing 15 replies - 1 through 15 (of 21 total)
  • yes, the theme being used is stored in a cookie so you have to check the cookie when a user switches their theme to display the right ad..

    That or you could hardcode the the file names right into the theme files.

    For #1.. I used to do something this to switch header images, (hopefully it will give you some ideas):

    <?php
    if($HTTP_COOKIE_VARS["wpstyle"] == "girl.css")
    { $thelogo = "vi-logo-girl.gif"; }
    else if($HTTP_COOKIE_VARS["wpstyle"] == "tree.css")
    { $thelogo = "vi-logo-tree.gif"; }
    else if($HTTP_COOKIE_VARS["wpstyle"] == "boy.css")
    { $thelogo = "vi-logo-boy.gif"; }
    else
    { $thelogo = "vi-logo-girl.gif"; }
    ?>

    You just have to figure out the name of the cookie, and what the theme name is being stored as.. Check your own cookies when you change themes ??

    By the way, in the example above, ‘wpstyle’ was the name of the stored cookie, and the relevant info I needed was the *.css

    It will work flawlessly if done correctly.

    Thread Starter andyspeed

    (@andyspeed)

    whooami, ‘wpstyle’ is the name of your cookie. This format is different to what I’ve found.

    I only find the cookie : [email protected]

    ???

    no, thats not the name of the cookie..thats what you see when youre looking in ie’s temp directory.

    I see your site in your profile, but dont see a place to switch themes.. where is it? ill tell you the name of the cookie, and the content.

    I found it .. one sec..

    youre using ryan’s theme switcher and it assigns cookienames using random strings.. so, upon changing the theme on your site my cookie name was:

    ‘wptheme44f9fd767eab548321032aeb509ffdb8’

    and the content of the cookie was: fMulti

    You can do what I explained, and take the time to figure out the regex needed to capture the random string after ‘wptheme’ in the above example, OR, you can edit his code so that the extra string of stuff is not tacked on.

    If you do the editing of the theme switcher, its very simple to do this:

    <?php
    if($HTTP_COOKIE_VARS["wptheme"] == "fMulti")
    { $myad = "black-ad.php"; }
    else if($HTTP_COOKIE_VARS["wptheme"] == "Fast+Lane")
    { $myad = "white-ad.php"; }
    else
    { $myad = "white-ad.php"; } //default theme
    ?>

    Thread Starter andyspeed

    (@andyspeed)

    Ok thanks whooami

    This is part of the code of the theme switcher. To make my cookie without the extra string of stuff is not tacked on, which part would I be wanting to edit out?


    function ts_set_theme_cookie() {
    $expire = time() + 30000000;
    if (!empty($_GET["wptheme"])) {
    setcookie("wptheme" . COOKIEHASH,
    stripslashes($_GET["wptheme"]),
    $expire,
    COOKIEPATH
    );

    $redirect = get_settings('home').'/';

    if (function_exists('wp_redirect'))
    wp_redirect($redirect);
    else
    header("Location: ". $redirect);

    exit;
    }
    }

    Once I’ve got that I think I’m sorted.

    its cookiehash, BUT..

    Im looking at the file right now.. so hang on ??

    there are alot of instances of that.. youre prolly going to be better off just trying to grab the cookie, complete with the hash. Let me mull this over for a few minutes, and ill repost what I come up with.

    instead of just wptheme, try this:

    <?php
    if($HTTP_COOKIE_VARS['wptheme'.$COOKIEHASH] == "fMulti")
    { $myad = "black-ad.php"; }
    else if($HTTP_COOKIE_VARS['wptheme'.$COOKIEHASH] == "Fast+Lane")
    { $myad = "white-ad.php"; }
    else
    { $myad = "white-ad.php"; } //default theme
    ?>

    im just tossing this out, might work, might not.

    Also, you really dont need the else if in that, your checking to see if the black theme is chosen, if its not, then you use the default. Follow?

    Thread Starter andyspeed

    (@andyspeed)

    No, nothing appears there

    Thread Starter andyspeed

    (@andyspeed)

    Also, you really dont need the else if in that, your checking to see if the black theme is chosen, if its not, then you use the default. Follow?

    Yes that’s true. Because if you’re not on the black then you’re on the white, which is the same as default anyway

    try the same but use cookiehash without the caps ..

    Thread Starter andyspeed

    (@andyspeed)

    Unfortunately not, both Caps and non-caps have been tried. I feel that there is a greater chance of this working if we had a cookie without a long string. Unfortunately I don’t know how to get to this yet.

    well you can edit the plugin file accordingly to remove ALL instances of $cookiehash, for instance,

    if (!empty($_GET["wptheme"])) {
    setcookie("wptheme" . COOKIEHASH,
    stripslashes($_GET["wptheme"]),

    would be:

    if (!empty($_GET["wptheme"])) {
    setcookie("wptheme",
    stripslashes($_GET["wptheme"]),

    and so on..

    Thread Starter andyspeed

    (@andyspeed)

    Removing ALL instances of Cookiehash from the plugin file renders multiple themes unusable and it reverts to the default theme.

    That can’t be the solution then…

    yap, its in the core. ill mess around with it on my sandbox a bit.. gimme a little time.

    actually, the answer is in the plugin.. since if you look it checks the cookie in order to create the selector:

    if ((!empty($_COOKIE["wptheme" . COOKIEHASH]) && $_COOKIE["wptheme" . COOKIEHASH] == $theme_name)

    Note that $_COOKIE and $HTTP_COOKIE_VARS are essentially the same; one uses globals, one doesnt (if I remem. correctly).

    So.try this:

    <?php
    if($HTTP_COOKIE_VARS["wptheme".COOKIEHASH] == "fMulti")
    { $myad = "black-ad.php"; }
    else if($HTTP_COOKIE_VARS["wptheme".COOKIEHASH] == "Fast+Lane")
    { $myad = "white-ad.php"; }
    else
    { $myad = "white-ad.php"; } //default theme
    ?>

    i figured it out .. hang on.

Viewing 15 replies - 1 through 15 (of 21 total)
  • The topic ‘Adsense/Theme switcher issue’ is closed to new replies.