Display Google Docs spreadsheets in WordPress Pt2
15 Comments
Following on from our post on how to use Google Docs as a lightweight CMS, this is how to include editable tabular data with custom fields in your WordPress theme.
Edit core WordPress theme files
You will only need to edit two files in your theme:
header.php
single.php
Copy the contents from the source code in my previous post:
And paste it into header.php
Add the .csv spreadsheet reader php to single.php
After the line
Read the rest of this entry »'); ?>
paste in the following code
";
# open the csv
$handle = fopen($csv, "r");
$data = fgetcsv($handle, 1000, ",");
echo "";
# column headers from 1st row of csv:
foreach($data as $value) {
echo "$value ";
}
echo " \n\n";
# data rows:
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
echo "";
foreach($data as $value) {
# write table cell data
echo "$value ";
}
echo " \n";
}
echo "\n\n";
}
else { echo "Can't connect to google, sorry!"; }
?>
This is the same as from the previous post, but this time we will remove the following line, as we will pass the .csv url dynamically
# set your csv spreadsheet url here
$csv = "http://spreadsheets.google.com/pub?key=t6wIcgSnjd6eJX1NbaOqWtg&output=csv";
Look for the .csv Custom Field
In single.php
, change the following line from
to
ID, 'csv', $single = true);
?>
This will check for Custom Fields with the name of ‘csv’
Add a Custom Field to your post
With both files saved, log in to your WordPress admin, and create a new post. Below the post and excerpt textareas, under Add custom field, set the Name to ‘csv’ and the value to the url of your Google Docs spreadsheet (or any .csv on the web) – in this case http://spreadsheets.google.com/pub?key=t6wIcgSnjd6eJX1NbaOqWtg&output=csv.
Press Publish and admire your spreadsheet! Obviously, your theme will need to be big enough to accomodate your table! Any amendments to your original document will be updated on your post – great for collaborative data or dynamically generated spreadsheets.
[…] Display Google Docs spreadsheets in WordPress […]
[…] Display Google Docs spreadsheets in WordPress […]
[…] Display Google Docs spreadsheets in WordPress […]
[…] Display Google Docs spreadsheets in WordPress […]
[…] Display Google Docs spreadsheets in WordPress […]
[…] Read more: Display Google Docs spreadsheets in WordPress Pt2 – Blackspike.com […]
[…] Display Google Docs spreadsheets in WordPress […]
[…] Display Google Docs spreadsheets in WordPress […]
[…] آموزش ساخت لیست رخدادها در وردپرس نمایش صفحات گسترده Google Docs در وردپرس چگونه پایگاه داده وردپرس را بهینهسازی […]
[…] نمایش صفحات گسترده Google Docs در وردپرس […]
Ahhh this is exactly what I’m looking for but can’t get it to work. =( I’m trying to implement it in a Page as opposed to a Post so I’m editing page.php instead, but that shouldn’t matter, right? When I make all these changes, everything just breaks and I get the white page of death. =/
That seems weird… I’ll email you in a minute so you can send me your theme and take a look
I got it working. Great stuff! Now if I could make that data searchable via the WordPress search function, that’d raaawk!
Thanks for sharing this. =)
Sorry, forgot to post my fix for anyone else that comes across this. I just had to increase my PHP Memory Limit.
Great post!
Im interesting to this with page instead of post, how to do that?
tnx