WordPress.org

Forums

[resolved] variables (3 posts)

  1. charismaarts
    Member
    Posted 2 years ago #

    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

  2. keesiemeijer
    moderator
    Posted 2 years ago #

    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.

  3. charismaarts
    Member
    Posted 2 years ago #

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

    Gerard

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.