single post with meta


Include external PHP files and list documents in a directory


In my search for a way to : a) easily generate a list of a large number of PDF documents in a folder on the server; b) automatically show links to each document for easy download, and of course c) display this within a WordPress Page or Post (whew!), I discovered the WP Include File plugin from and this directory lister script (thanks to

How I did it

With a bit of experimentation, I was able to do it like this :

  1. I created a folder for the PDFs at my client’s site root and named it logically (i.e. “pdf”)
  2. Inside this folder, I put the PDF files and added the script as a file called index.php
  3. I then created a WordPress Page for the list and used the WP Include File shortcode to include index.php file with the plugin. The shortcode looked like this (I’ve added an extra space after/before each bracket so you can view the code in this page) :
    [ include file="MyCustomFile.php" masterpath="/home/myusername/myrootdirectory/thefilefoldername" ]

The hardest part was figuring out the proper path for the shortcode and adding hooks/html to index.php to style the list of PDFs. WP Include File has several settings options, but I ended up using what they call the “masterpath” option directly in the shortcode (as shown above). You can download my adapted version of the script here and see how I did it, and view a page with a list of PDF documents generated using the script (it could be other types of documents or images, too).

Comments are closed.