The education news website Chalkbeat provides local coverage of critical issues, including following education-related legislation every spring. Many state agencies provide the status of current legislation on their websites, but aggregating and embedding that data using an iframe wasn’t very attractive.
So, I wrote a little WordPress plugin that uses cURL to grab the HTML from a URL and then some regex to find a specific table by ID and echo it out on the page. That way, the table uses your site’s stylesheets and is just as pretty and responsive. The current table data is pulled every time the page is loaded and a handy shortcode makes it simple to grab tables from multiple sources.
Please only use this to grab tables you are allowed to embed, and not for nefarious things like passing someone else’s content off as your own. To that end, the basic framework for this plugin came from the smart folks on this Stack Overflow discussion.
The current plugin is available in the WordPress plugin repo.
General usage:
[getthetable url="page url" id="table id" tablesorter]
The following example below will grab the table below for testing on your site. The optional tablesorter argument loads the tablesorter js and css from the cdn.ucb.org.br CDN and applies it to your table, making it sortable:
[getthetable url="http://www.itjon.com/getthetable/" id="getthetable" tablesorter]
First Name | Last Name | Age | Total | Discount | Difference | Date |
---|---|---|---|---|---|---|
Bruce | Almighty | 45 | $153.19 | 44.7% | +77 | Jan 18, 2001 9:12 AM |
Bruce | Evans | 22 | $13.19 | 11% | -100.9 | Jan 18, 2007 9:12 AM |
Bruce | Evans | 22 | $13.19 | 11% | 0 | Jan 18, 2007 9:12 AM |
Clark | Kent | 18 | $15.89 | 44% | -26 | Jan 12, 2003 11:14 AM |
John | Hood | 33 | $19.99 | 25% | +12 | Dec 10, 2002 5:14 AM |
Peter | Parker | 28 | $9.99 | 20.9% | +12.1 | Jul 6, 2006 8:14 AM |
* This sample table came from http://tablesorter.com/docs/