WordPress.org

Ready to get started?Download WordPress

Forums

Assign and modify php values across templates (3 posts)

  1. rodrigue
    Member
    Posted 1 year ago #

    Hi, I am trying to check for a php variable in each of my template in order to assign it a different styling but the value seems to disappear, can you please help, I already spent hours trying to figure this out. I know there is something small I'm missing.

    So here is everything:

    I have a page a which links to b and pass a value in the URI as http://www.b.com/?value=h

    now the b file receive the value and change the global variable's value to the one passed in the URI, then redirect back to the page.

    This is the code in my b file:


    $server = $_SERVER["REQUEST_URI"];
    $valuePos = stripos($server, "=");

    $nodes = substr($server, ($valuePos + 1));
    $endPos = stripos($server, "e");
    $gender = substr($server, ($valuePos + 1), ($endPos));

    $valuePos = stripos($nodes, "-");

    $redirecturl = substr($nodes, ($valuePos + 1));

    header( 'Location: '.$redirecturl );

    $gender is the global variable that I have declared in function.php, I have set its default value to neutral.

    Now when I try to access $gender from another template it just displays the default value (neutral). Please help

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    I am trying to check for a php variable in each of my template in order to assign it a different styling

    Use the body_class() function on your theme's header.php template file and each of your custom page templates will have its own unique class.

  3. rodrigue
    Member
    Posted 1 year ago #

    thanks esmi for your response. I already got a solution though. I used the $_SESSION class.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags