Script: creating categories of GM entries (PHP)

domesticat's picture

In its current form, Greymatter (which I use on domesticat.net) cannot file entries into categories, because there is no such variable. The most common workaround is to post under different author names.

However, there isn’t an easy way to sort entries into a list based off of these categories. In fact, when I recently created poetry and recipe pages for cat.net, I had to update the list of entries manually when I added a new entry in that section.When it comes to maintaining domesticat (or geek-chick.net for that matter) my mantra is, “Automation GOOD!” I’d discussed with friends the possibility of creating a “code snippets” page and a “movies” page, but I truly wasn’t interested in doing such a thing if I had to maintain all these pages manually. I am not a coder. If I’m anything, I’m a writer. I want to write, and let the back-end code post, archive, and sort my work.

While looking at Heather’s site, smattering.org, I realized that she was probably manually adding a new line to the list of Friday Five links every time Friday rolled around. I sat there for a few minutes and thought…well, why don’t we just pull all this stuff from the gm-entrylist file and automate it? I hate thinking about this sort of thing, and I’m sure everyone else does too.

The nice thing about this script is that it’s pretty easy to modify; I commented it heavily. You can search for any text string that might show up. So, you could search for posts by a particular author, with a particular text string in the subject, or for just extended (or regular!) entries.

Format the output any way you like. On the recipes and poetry pages, each matching response is dished out in the form of a list item, but you could also make each hit an option in a dropdown list. (This method would be good if you expect to have a lot of results but don’t have a lot of space; it’s how I do my archives page.)

There is a very, very interesting possibility inherent in this script. With a small amount of re-coding, it could be set up to automatically create an “On This Date” script: providing links to entries that you wrote on the same day in previous years. Since date-of-post information is included in the entrylist file, this is completely feasible.

I might just have to do that. I’ve always thought that would be a neat thing to have, but I didn’t want to have to go through the mess of coding such a thing by hand every time I made a post.

If you’re interested in acquiring such a beastie, add a comment to this post and I’ll keep it in mind.

To use the script, download the categories.zip file and get the text file out of it. Edit it to suit your site; there are plenty of comments in there to give you some guidance. I’ve currently got this code pasted into my recipes and poetry pages, but I’d think that you could also call it through an include() function.

Maybe I should create that “code snippets” page after all….

gfmorris's picture

You're not a coder, yet you keep coming up with things like this ... :D
Demetrios Panagiotopoulos's picture

Hi . I would like to use this script and I'm having a bit of trouble getting it to run . Does this script have to be in a Greymatter template? I see the url to your "bestof" page is http://www.domesticat.net/content.php?q=writing. The page that I have the script on is http://www.ficc.biz/newsroom/fbbc_newsroom.php . Curious as to why your url ends w/ a "?". If you have any ideas at all about the preceding questions I would greatly appreciate to hear them! Sincerely, Demetrios
gfmorris's picture

To use this specific script, you'd have to be using GM, I think.
domesticat's picture

The script is PHP, and thus runs completely independent of GM -- it will not be in a template. The script reads a GM-produced file (the entrylist) and generates output based on that. If you truly don't know why the URL ends with a question mark, let me recommend two things: 1) Read this page to find out what it is. 2) Do some basic reading up on PHP before you install PHP scripts. Despite the fact that I know the safety of my script, you do not. You should never, EVER install scripts that you don't understand (or whose author you can't personally strangle). In this case, it sounds like you're new to PHP, and you would be GREATLY benefited by learning the basics of the language before you start tinkering with scripts. I realize you don't want to hear 2). When I started, I didn't want to hear it either. Life's terrible that way.
gfmorris's picture

Feel free to delete my uselessly wrong comment ... and this one to boot. :p
Demetrios's picture

Thanks to you both for the info, the link and the humor! :)
Demetrios's picture

Amy, I finally got the site up and running (and learned a bit of PHP along the way) thanks to your help! Regards, Demetrios
etcetera's picture

i'm new to this =/. do we put the categories file into our archives index.php file? thanks in advance

Post new comment

User login

Recent comments

  • Anonymous 5 days 6 hours ago [view]
  • albert (spain) 3 weeks 5 days ago [view]
  • Kelly | Mens Suits 4 weeks 2 days ago [view]
  • Anonymous 5 weeks 1 hour ago [view]
  • Suzanne Nelson 5 weeks 3 days ago [view]

Search

Hello, anonymous!

If you're seeing this, you're not logged in. A lot of content here is only visible if you're logged in, and comments by anonymous users are held for moderation. Consider getting an account to save yourself some frustration?

domesticat.net

is the home of Amy Qualls-McClure since 2000. She is a Drupal / quilt geek in Huntsville, Alabama. One spouse, two cats, no kids, lots of opinions.

Public account for work and Drupal stuff: Private account for friends and personal life:

me on plurk me on drupal.org my music habits on last.fm my photos on flickr my bookmarks on del.icio.us my bookmarks on pinboard.in Amy Q. on foursquare what I'm reading

Some content is locked. Copy these links AFTER logging in for a query string giving you full feed-reader access:

Atom feed, entries RSS feed, entries RSS feed, comments