I’m trying to post smaller pieces of code as they come up to better document things for myself and maybe it’ll end up helpful for others. So these things aren’t terribly exciting and may, in fact, be boring. The Context I set up a custom post type named “Cards” and another custom post type named “Updates” shows up under the cards. There’s a front-end Advanced Custom Fields form that automatically tags the update with the title of the card. We had a problem where some of the updates were getting tagged but were not showing up where they should. Turns out I had originally set the code to look for the slug (post_name) so I could use that in the show updates query more easily.1 The problem was that when a post is first saved the slug is generated at that point. If the title gets changed down the road, the slug doesn’t automatically update. That was our problem. A post might initially be titled TRM Something and then be re-titled TRLM Something. It’s a hard thing to spot even if you knew to look at the slug portion of the permalink. All the following code does is sync up the slug with the title. It’s hooked to the acf/safe_post action but could be tied to more any of the […]
We had a list of rampages sites in a Google Spreadsheet and wanted to know when they were created. I started to look that up but only managed to do it twice before I gave up and went in search of another way. In this case it took two little bits of code. This first piece is active on our generic site-wide plugin. It adds the blog’s creation date, last updated, and post count to the base JSON data. That’ll be handy in the future if we want to checkup on sites with only one query rather than multiple queries. This second piece is a Google Script that makes a function that I can call in the sheet by typing =getCreationDate(“http://someurl.com/”) The two together answer my immediate problem but the JSON modifications have some long-term value for us and might be useful to someone else.
flickr photo shared by Internet Archive Book Images with no copyright restriction (Flickr Commons) Sometimes you want a Google Sidebar element to be able to pull variables from a Google Script. The key element is google.script.run.withSuccessHandler. I’m still not entirely sure I have this in my head deeply/correctly but this is functional and might help someone else (even if that someone is just me at a later point in time when I’ve forgotten this). This one sets some default times based on spreadsheet variables stashed elsewhere and then automates some date/time entries using the form sidebar. Sidebar Code Google Script Code The entire sidebar/script setup is below in case anyone cares for some reason. Pick Your Date Start/End Times Start: End: Hide Previous Dates Submit
flickr photo shared by CraigMoulding under a Creative Commons ( BY-SA ) license Just two little functions in Google Sheets that came up as we tried to quickly pull comments from a blog for some other work. It was an odd scenario but the techniques should have other useful applications. IMPORTFEED The function below pulls my 10 most recent comments into a spreadsheet. You can set it to pull more but will also need to change the number of items in your RSS feed. You can find that setting under Settings>Reading. It’ll work on any RSS feed and there are a variety of other IMPORT functions that are worth checking out. This could be a useful option if you wanted to analyze the comments in one place or if you wanted to look a bit more deeply at comments on sites you don’t control. 1 1 I had to switch this to code because copy/paste led to issues with quotes messing up the formula.
Making shareable (Sharing with a single person or specific group but not with the world.) comments on public writing is a fairly awkward spaaaaaace right now. There are things like AnnotateIt and Awesome Screenshot and the annotations in Diigo. So I’m looking around for other free options and brain storming odd ideas and not find a whole lot and I came up with the following . . . Note: I’m not saying this is a good idea, it may even be a bad idea but it might inspire someone to do something more interesting down the line.1 I at least found it mildly amusing. Here’s how you might pull an author feed from WordPress into Google Spreadsheets with separate cells each paragraph (for paragraph level commenting). The idea being that you can share the Google document with just that student and do the commenting via the GSS commenting feature. Google spreadsheets will import lots of things (xml, atom, rss). WordPress provides lots of specific feeds (author, tag, categories, combinations thereof). So step one is to get the author feed – for example http://rampages.us/fren330/author/sheehantm/feed/. You can then use the IMPORTXML formula in GSS to import that XML and do some XPATH parsing of the pieces. In this case I used =IMPORTXML(“http://rampages.us/fren330/author/sheehantm/”,”//p”) to pull out the paragraphs. I can then share the […]
I often want to know just a bit more about numbers I see in tables. As I was looking at some thing today, I stumbled on the Wikipedia page for “List of Most Viewed YouTube Videos“. After being more than a bit amazed at the utterly staggering numbers. I wanted to know what they translated to in terms of years because the numbers were just too big. I remembered that Google Spreadsheets will let you pull in a table from a website with no fuss. All I needed to do was put =IMPORTHTML(“http://en.wikipedia.org/wiki/List_of_most_viewed_YouTube_videos”,”table”,1) in the first cell on the spreadsheet and viola the table is transcluded. I can now add a few more calculations to figure out the import stuff – like how many years worth of time have been spent watching Gangnam Style (16,274.24 years for the record1). You can go mess around with the data here. 1 Assuming I didn’t screw something up.