SO, I have some php that I'm inserting into a widget that generates a list of pdfs within a directory on the root level of my wordpress install (see "Meeting Summaries" to the right here: http://mt-spacehosting.com/fisheries/plans/northeast-multispecies/ ). The list is populating as it should, but when one of the options is clicked, the url adds the current page structure of the current url.

To see the code below working correctly, you can visit: http://mt-spacehosting.com/fisheries/past-events.php a simple php page I uploaded to the root directory of the install.

Here's my code:

    <select name="s1" onchange="MM_jumpMenu('pdfwin',this,0)">
          <option value="Select Date" selected="selected">Select Date</option>

    $sub = ($_GET['dir']); 
    $path = 'groundfish-meetings/';
    $path = $path . "$sub"; 
    $dh = opendir($path); 

    while (($file = readdir($dh)) !==   false) { 
        if($file != "." && $file != "..") { 
            if (substr($file, -4, -3) =="."){
             echo "$i. <option value='$path/$file'>$file</option>";
             } $i++; 
         } closedir($dh); 

I tried $path = "'.bloginfo('url').'/groundfish-meetings"; to set a base url, but it broke the list and none of the files showed.

Any help / thoughts would be appreciated!

Thanks, Matt

  • I moved the same exact code to a homepage widget and the dropdown functions as it should: mt-spacehosting.com/fisheries But, I need it to function on the subpages as well.
    – mtuttle
    Aug 6, 2013 at 17:53

1 Answer 1


You are using paths relative to the current directory.

Try this (untested)

echo "$i. <option value='" . home_url('/groundfish-meetings/' . $file) . "'>$file</option>";
  • Perfect! I thought that specifying the past would make it an absolute location, especially since it was finding the files on the server and populating the list. Thanks for the help!
    – mtuttle
    Aug 6, 2013 at 18:32
  • Any thoughts on ordering the list by upload date?
    – mtuttle
    Aug 6, 2013 at 18:33
  • That part isn't really WP specific. This answer might point you in the right direction though.
    – vancoder
    Aug 6, 2013 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.