SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    It's been real... Forbes's Avatar
    Join Date
    Dec 2004
    Location
    Yorkshire, England
    Posts
    676
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Using "require" function in header.php within WordPress

    Hi guys!

    I know there's a forum on the WordPress website, but I've had no joy over there, so I thought I'd ask here instead.

    I've developed a navigation system, which I want to use within WordPress. The system itself is a class file. I'm using the "require" function to pull in the file, I then instantiate the class and then call the methods to build the navigation.

    This all works fine in the web pages I've created for the regular website, but I can't find the correct path for my folder "library" (which contains the class fine) which is on the root.

    I've tried everything I know but I can't get at the root from within the "header.php" file.

    Any ideas?
    Last edited by Forbes; May 19, 2009 at 06:34. Reason: Un-screwing the screwed up formatting...

  2. #2
    SitePoint Addict joaquin_win's Avatar
    Join Date
    Jul 2005
    Location
    Venezuela
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What have you tried?

    Try using $_SERVER['DOCUMENT_ROOT'];

    Also read this for more info: http://ca3.php.net/manual/en/reserve...les.server.php

  3. #3
    It's been real... Forbes's Avatar
    Join Date
    Dec 2004
    Location
    Yorkshire, England
    Posts
    676
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi!

    Yeah, that was the first thing I tried after a merry sprinkling of "../../" to back up to the root.

    Nothing happening I'm afraid...

  4. #4
    SitePoint Addict joaquin_win's Avatar
    Join Date
    Jul 2005
    Location
    Venezuela
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, if you are making a wordpress theme, the right thing should be to place the file with the class in the theme's directory. Then it should be easier to gain access to it and include it.

    Have you tried that?

  5. #5
    It's been real... Forbes's Avatar
    Join Date
    Dec 2004
    Location
    Yorkshire, England
    Posts
    676
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The class file is huge and doing that would totally defeat the purpose of having a class file in the first place.

    Plus, the class file itself refers to other class files. So making all of this work would be truly onerous.

  6. #6
    SitePoint Addict joaquin_win's Avatar
    Join Date
    Jul 2005
    Location
    Venezuela
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, so back to basics: what error are you getting?

  7. #7
    It's been real... Forbes's Avatar
    Join Date
    Dec 2004
    Location
    Yorkshire, England
    Posts
    676
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just the standard error messages:

    Warning: main(path/template.php) [function.main]: failed to open stream: No such file or directory in path/header.php on line 3

  8. #8
    SitePoint Addict joaquin_win's Avatar
    Join Date
    Jul 2005
    Location
    Venezuela
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And you tried include('/home/berryman/public_html/file.php')?

  9. #9
    SitePoint Enthusiast shoby's Avatar
    Join Date
    May 2009
    Location
    USA
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is anyone a freelance wordpress developer?

  10. #10
    It's been real... Forbes's Avatar
    Join Date
    Dec 2004
    Location
    Yorkshire, England
    Posts
    676
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by joaquin_win View Post
    And you tried include('/home/berryman/public_html/file.php')?
    Yep, tried that. All the way down to the server root.

  11. #11
    SitePoint Addict joaquin_win's Avatar
    Join Date
    Jul 2005
    Location
    Venezuela
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It doesn't make sense that you cannot include it, have you checked file permissions? Does the apache user have read permissions on the file?

  12. #12
    It's been real... Forbes's Avatar
    Join Date
    Dec 2004
    Location
    Yorkshire, England
    Posts
    676
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by joaquin_win View Post
    It doesn't make sense that you cannot include it, have you checked file permissions? Does the apache user have read permissions on the file?
    There aren't any issues with permissions or Apache. If there were, nothing at all would work.

  13. #13
    SitePoint Addict joaquin_win's Avatar
    Join Date
    Jul 2005
    Location
    Venezuela
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I didn't refer to all files but that one in specific, file permissions are set on each file.

    Have you tried creating a test.php file right beside the file you want to include and including it from there to see if that works?

    test.php
    PHP Code:
    <?php
    include('file.php');
    //Some test code here (instantiate the class)
    ?>

  14. #14
    It's been real... Forbes's Avatar
    Join Date
    Dec 2004
    Location
    Yorkshire, England
    Posts
    676
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by joaquin_win View Post
    I didn't refer to all files but that one in specific, file permissions are set on each file.
    Like I said in the thread opener, the navigation works fine in the web page I created and built the system in. There are no permission errors at all.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •