WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] variables

[Resolved] variables

  • charismaarts
    Member

    @charismaarts

    Hello:

    I think I know the answer to this but I am not sure so I somebody can explain. I want to store a variable on a page; let’s say the varible is “$ZC”. I thought the variable would be remembered at any point on the page; but since I set the variable in the “single.php” file; when I try and access the variable in some code in the “single-content.php” file the value is lost; even though both pieces are running on the same post. the variable is set way at the top of the page before header is set; and then I try and access it in the “post content” area; but it seems to be lost. Is it because I am in a different php file? even though I am in the same post? to carry across a variable from one php file to another like this; are the only ways to this session variables and cookies? Please let me know…

    Thanks,

    Gerard

Viewing 2 replies - 1 through 2 (of 2 total)
  • keesiemeijer
    moderator

    @keesiemeijer

    You can make it a global variable in header:

    <?php
    global $ZC;
    $ZC = 'hello';
    ?>

    and use it in other template files by declaring it first:

    <?php
    global $ZC;
    echo $ZC;
    ?>

    Or use include() to get the other template files:
    http://php.net/manual/en/function.include.php

    Any variables available at that line in the calling file will be available within the called file, from that point forward.

    charismaarts
    Member

    @charismaarts

    thanks for your answer keesiemeijer; i will see if i get that to work…

    Gerard

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] variables’ is closed to new replies.