WordPress.org

Ready to get started?Download WordPress

Forums

Changing theme (6 posts)

  1. fdmitry
    Member
    Posted 3 years ago #

    Good evening, guys!

    I wanted to ask your help to realize one of my ideas.

    My website works on some theme. I can access it by typing just a domain name (so by index.php).
    Can I make following trick?

    If someone will access my website, as an example, from index2.php - website will load a different style.css (or different theme) for homepage and all following pages, that user will watch.

    For example, by index.php I can see a full version of my blog, but by index2.php I will see all pages of blog without, let's say, sidebar.

    Can we realize it?

    Thanks for your help and hope for answers!
    This question is really interesting for me, because it opens new huge posibilities for my blog ;)

  2. fdmitry
    Member
    Posted 3 years ago #

    Up? :D

  3. MrGamma
    Member
    Posted 3 years ago #

    Yes... Let's say you have a page called index2.php you can put this code in it, in the same root folder where index.php is (please note I do not use wordpress)

    <?php
    require('index.php');
    ?>

    Once you have done that, test to see if you can access the website as you usually would. If that works... then inside your wordpress files, look for this line of code... (I looked at the source code of this website to make the line of code below)

    <link href="http://s.wordpress.org/style/style.css" type="text/css" rel="stylesheet" />

    Now... that is the link to the external spreadsheet... So where ever it is inside your wordpress files you should be able to do somthing like this.

    if($_SERVER['PHP_SELF'] == 'index.php'){
    echo '<link //----the rest of the code for the first spread sheet.
    }else{
    echo '<link //----the rest of the code for the second spread sheet.
    }

    This is a link to the php documentation on the server variable. This tells you the entire "State" of the application or the information which is currently held in the SERVER global variables.

    Variables are just a fancy term for something that contains data. Keys and Data.

    http://www.php.net/manual/en/reserved.variables.server.php

    So try doing this as well... find the line of code that has the link to the external spreadsheet, and then, print this in the php code and see what the variables look like when you call it through the index.php file and then see what it looks like through the index2.php file.

    // NOTE: I tried to put a pre-format tag here but the comments took it out so I am writing the greater than and less than html traingular brackets in square brackets instead...

    print([pre]);
    print_r($_SERVER['PHP_SELF']);
    print([\pre]);

    That way you can get the right filename and path for use with the if/else switch which decides which html line to print.

    Is this making sense to you? I am subscribed and pretty much taking easy today so let me know if I can help.

    I am not a wordpress, so there is always a possibility that there are many other different ways to do this.

  4. fdmitry
    Member
    Posted 3 years ago #

    Let's say I understood your idea, except for this part:

    if($_SERVER['PHP_SELF'] == 'index.php'){
    echo '<link //----the rest of the code for the first spread sheet.
    }else{
    echo '<link //----the rest of the code for the second spread sheet.
    }

    If you are not occupied, can I contact you somewhere please?

  5. MrGamma
    Member
    Posted 3 years ago #

    Well, lets explain it in English. When the website runs... you just need a way to add a "marker" or there need to be something different about the internal code that you can use to tell the website to do something different.

    In this case, you want to make a different file name called index2.php

    It could also be done by accessing a different domain name too, right?

    Or even a different sub-domain.

    So the only thing we have to do is be able to know when the different domain, sub-domain or file is called. Right?

    the $_SERVER variable holds all the information coming through the website, in terms of which domain is being called, which file name is being called, even the IP address of the the person accesing the website, so if you wanted to, you could serve somebody different content that everybody else.

    So...

    if($_SERVER['PHP_SELF'] == 'WHAT I EXPECT'){
    // do this
    }else{
    // do that
    }

    Is that making sense?

    Try printing out this... I use it all the time, it is the best way to get a good eye view of what is happening. Only don't use square brackets. Use HTML brackets. So put this in two different files... The first one in index.php

    <?php

    print([pre]);
    print_r($_SERVER);
    print('[/pre]');
    ?>

    and then in index2.php do the same and you will see the print out from each one is different.

    So that makes the

    if(){ }else{}

    statement make a decision based on what the $_SERVER globals are equaling.

    I am not really anywhere except on twitter or on email, but you can contact me at james@sitebyjames.com - I am not skype or anything.

  6. fdmitry
    Member
    Posted 3 years ago #

    I am contacting you right now.
    If anybody has another ideas, suggestions or other stuff - don't hesitate to comment here ;)

Topic Closed

This topic has been closed to new replies.

About this Topic