• Resolved dc_photo

    (@dc_photo)


    Guys,

    I am modifying the toolbox theme.
    I wrote a ‘whatever.php’ file, and put it under:

    wp-content/themes/toolbox/php/whatever.php

    Now, if I just include it in index.php, it works fine. When I try to pass variables however like this:

    include(‘php/whatever.php?myvar=3’)

    , it breaks down.

    I understand (from the php manual) that I need to include the full path for this to work. However, attempts like:

    include(‘http://mysite.com/wp-content/themes/toolbox/php/whatever.php?myvar=3’)

    of course fail…

    What am I doing wrong? Or is it simply not possible to do this – as I think I read?!

    I know I could use global variables, but I don’t really want to.

    Many thanks
    D.

Viewing 7 replies - 1 through 7 (of 7 total)
  • esmi

    (@esmi)

    Why are you including a template file?

    Thread Starter dc_photo

    (@dc_photo)

    Because I need to generate for my page 30 similar html elements which vary depending on these variables … but does it really matter?

    esmi

    (@esmi)

    Yes. The more we know about what you are trying to achieve, the better the chance that we can come up with a workable solution. For example, why not use a function in functions.php instead of whatever.php and pass your variables as function arguments?

    Thread Starter dc_photo

    (@dc_photo)

    Ah, ok. So you mean transfer the content of whatever.php into functions.php and then simply call it from say index.php whenever I need it? OK, I think I got it.

    But still just to confirm, what I was trying to do is not possible, is it?

    Many thanks for your help!

    esmi

    (@esmi)

    So you mean transfer the content of whatever.php into functions.php and then simply call it from say index.php whenever I need it?

    Yep. Using a standard PHP include in WordPress is always dicey because of the way in which the whole templating system works.

    Thread Starter dc_photo

    (@dc_photo)

    I just transferred it to functions.php and it works like a charm, many thanks again!

    esmi

    (@esmi)

    Glad I could help 🙂

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘pass variable to a php file’ is closed to new replies.