I have a post that includes a relatively large table that gets updated frequently. Instead of using the (slower) web interface to update the post each time, I installed one of the “run PHP” plugins and put a short bit of PHP code in the table body that opens an external file on the server and puts that in the table in the post. This way, I can edit the file locally in a responsive text-editor as needed and the change is reflected immediately when the the page is served (and without requiring any changes to any of the WordPress tables).
This works pretty well and I am generally satisfied with it, but there is a small catch in that the path to the external text-file is relative to the store on the server (I used the media-library manager to store it, and because I’m using the multi-site feature and PHP is server-side, the path is of the form
So I’ve got two questions:
- Is there a better way to include external content in a post than using PHP?
- (well, 1b.) If not, is there a better—ie, more consistent—way of accessing the files? (That is, a way to have PHP use URL-relative paths instead of server-relative paths?)
In the post, I have something like this (code is off the top of my head, so ignore any errors):
… <table> <thead><th>foo</th><th>bar</th><thead> <tbody> <?php $fn ="wp-content/blogs.dir/1/files/2011/02/foobar.txt"; $fh =fopen($fn, "r"); $data=fread($fh, filesize($fn)); //no clearstatcache; TXT file is not updated *that* often print($data); fclose($fh); ?> <tbody> </table> …
Where the text file contains something like this:
<tr><td>Blah</td><td>123</td></tr> <tr><td>Foobar</td><td>asd</td></tr> <tr><td>Test</td><td>555</td></tr> …
When the page is served, the PHP in the post is executed and pulls in the table rows from the external file, picking up any changes I made externally to it without having to go through WordPress to do so.
case 'a': element.style.backgroundImage='url(/blogs/foobar/files/2011/02/A.png)'; break; case 'b': element.style.backgroundImage='url(/blogs/foobar/files/2011/02/B.png)'; break; …