• I’m trying to write a function to include in my theme that opens a text file for input. Is there a WordPress variable I can use instead of the absolute file path?

    Instead of: $textfile = "blah/blah/blah/textfile.txt"

Viewing 6 replies - 1 through 6 (of 6 total)
  • Take a look at get_bloginfo

    Thread Starter zoion

    (@zoion)

    I can’t use an absolute path, I need a local path.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Use the get_template_directory() function.

    $path_to_theme_directory = get_template_directory();

    Also, that documentation on get_bloginfo was wrong, I’ve corrected it. It will also work for this case.

    Thread Starter zoion

    (@zoion)

    This is my setup.

    In theme:
    <?php include(TEMPLATEPATH . '/includes/random.inc.php'); ?>
    <?php if (function_exists('randomWit')) echo randomWit(); ?>

    In random.inc.php:
    <?
    function randomWit (
    $textfile = "long local path to/random.txt" ){;
    if ($quotes = @file("$textfile")) {
    $quote = rand(0, sizeof($quotes)-1);
    echo $quotes[$quote];
    echo ("");
    }};
    ?>

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    … Okay, but I fail to see how that’s relevant.

    What, exactly, are you asking? Could you rephrase the question, perhaps in a way that will let us know what you’re talking about?

    Thread Starter zoion

    (@zoion)

    In random.inc.php I’d like to not hardcode the local path to random.txt, but I don’t quite know how.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘referencing theme directory from custom function’ is closed to new replies.