Blog

  • Excluding a category in WordPress

    Over on my beer blog I have an entire section of "Press Releases" that I post but which I don’t want to show up on the main page or in the RSS feed—I don’t want to spam readers with excessive marketing but I like have the repository.

    Since I’m now using WordPress, I figured I’d simply grab a plugin that would do the work for me: exclude the category from my "content" portions of the site (like the front page and the feed) but still let people access that category directly so they could see the Press Releases if they so chose.

    To that end, I’d been using the "Category Visibility-iPeat Rev" plugin which seemed to do just the trick: I could configure exactly what category shows up in what area: front page, sidebar listings, search results, feeds, and archives. So I’d been using that up until now when I noticed a couple of bugs:

    • The individual category feeds weren’t working; that is, when you went to a specific category and added "/feed" to the end of the URL, the RSS feed would load for that category but it would be empty. These normally work in WordPress, and it’s a nice feature to have, and I wanted/needed it to work.
    • The plugin specifically excludes tags entirely (though unintentionally): any defined tags in the system were getting recorded into the database with all options off. I’m not using "tag browsing" anywhere on the site (yet), so this didn’t affect me, but I might in the future and other people are complaining about it.

    So I spent a little bit yesterday looking at the Category Visibility plugin code to see if I could fix the problem, and then looking at just adding the exclusion code myself to the theme so I could deactivate and remove the plugin entirely.

    I couldn’t find anything overtly wrong with the plugin code itself, and I didn’t want to spend too much time digging around WordPress’s core and driving myself insane, so I turned to adding exclusion code to my theme files.

    You want to exclude the category ID from the query before the code even runs what WordPress ominously calls "The Loop", so a call to query_posts() is in order. To exclude a specific category, you’ll do this:

    query_posts('cat=-3');

    The minus sign in front of the category ID (3 in this case) is the exclusion operator. If you omitted it, you’d be telling the query to only include category ID 3.

    So I dropped this line inside some logic to check if it was on the home page or the archives page (is_home() and is_archive(), appropriately enough) and then ran into another problem: paging back through "Older entries" was broken.

    Turns out just setting 'cat=-3' overrode the entire query WordPress was working with, so telling it to go to "/page/2" wasn’t registering. I dug around online and instead this is what you should do:

    query_posts($query_string . '&cat=-3');

    That preserves any other query variables that were passed to the system, like what page you were on, and still appends your category exclusion logic. Worked like a charm.

    All that was left for my goals was to exclude the Press Releases category from the site’s main feed. After digging around online some more, I determined that a filter hook needed to be applied to the feed query, and found some example code which I adapted to this:

    function exclude_pr_feed( $query )
    {
      if ( $query->is_feed ) {
        $query->set('cat', '-3');
      }
      return $query;
    }
    add_filter('pre_get_posts', 'exclude_pr_feed');

    That snippet was put into the theme’s functions.php file and performs the same exclusion logic as above, only when posts are being pulled and the feed output is being built. So far it suppresses Press Releases from the main feed but hasn’t affected the individual category feeds, including that for Press Releases. Which is perfect for my purposes.

    The nice thing is that this is overall a relatively minimal impact to the system and I save the overhead of Yet Another Plugin. And hopefully this will prove useful to someone else who wants to accomplish the same thing.

  • Tilting at windmills

    Two books are currently in my "active" pile right now (that is, that I’m actively reading):

    Beer in America: The Early Years 1587-1840, by Gregg Smith. Interesting, though I just started. Too soon to tell if it’s grabbing me as much as Ambitious Brew did.

    Don Quixote. The "Wordsworth Classics" paperback edition, and truth be told I’m slogging rather slowly through it; I have a theory or two as to why.

    First of all, it might be the translation; older or more "literary" translations seem to be drier, somehow, and lose the spirit of the original (e.g., rousing adventure story). I think a fresh(er) approach would work wonders.

    Second, and this might be a symptom of translation, the format is incredibly dense and hard to follow—small type with run-on sentences and dialog that are all combined in single paragraphs that can span pages. Just breaking up the dialog into eye-friendly chunks would work wonders.

    Finally, my current pet theory is that these classic literary authors were working without word processors, so editing and revising was such a pain in the ass that they just published first drafts. Which any editor will tell you are pretty unreadable.

    Cervantes could have shaved off a good 50,000 words if he’d just had access to a computer. It would work wonders.

  • My annual TV diatribe

    Seems like I do this every year, after the TV season has (mostly) ended. And year after year I seem to be watching the same damn shows. What’s up with that?

    Lost was better this year than it has been, but that’s still not saying much as they’ve continued to veer into left field for no discernible reason. Time travel, Egyptian mythology, the sudden retcon of Jacob into everyone’s lives… I swear they keep making this stuff up on the fly, don’t let any talk of a "master plan" tell you different. At this point I feel like I’m slogging through the show more out of inertia than anything. And sometimes it is a slog.

    24 started out strong but after the first four or six episodes it jumped the rails somehow. Actually, I have a theory about that: those first few episodes were first written and filmed last year, just before the writer’s strike shut down Hollywood and canceled the season of 24. So they were off to a good start, got shut down for a year (or six months, or whatever), then came back in (possibly with new writers? Not sure) and tried to pick up where they left off—but they’d already lost it. It was just a chore to watch, not unlike Lost.

    And what’s with the way it ended? Way too many loose ends and plotlines left dangling. It felt like it didn’t end, actually, which is a problem—not like a cliffhanger, which is a different beast, but like they had another couple of episodes to film and got cut short. Weird.

    I was not at all an Adam Lambert fan on American Idol this year. I’m glad Kris Allen won. That’s all I’ll say about that, other than having my faith restored in the collective good taste of the voting American public.

    The Office was probably my favorite show again this year. It’s just brilliant and hilarious, outstanding really.

    I loves me some Law & Orders, and though I’m a bit tepid on SVU, I’m loving this season’s plain-vanilla L&O and since Criminal Intent is finally back on with their new episodes, it’s one of the few shows I actually look forward to watching. (I know, the "new" CI episodes already aired on the USA channel before the NBC "season" started this month. I don’t watch USA, okay?)

    Scrubs was "back" on ABC this time around and it was good… but not as good as before. Just wasn’t feeling it as much. Though I thought they handled the series finale really well.

    I started watching The Unusuals and was rather enjoying it, so naturally ABC decided to cancel it. (They were probably sick of my bitching about Lost.) Quirky characters, fast-paced, no overall "mystery storyline" that would require three years to unravel… just a decent cop show.

    Speaking of decent cop shows (or not), one thing I simply do not understand is how CSI: Miami can continue to be on TV. It’s the most ridiculous show I’ve ever seen. The only redeeming quality is the opening one-liner. And it seems like even that is starting to consume itself lately.

    Of course, when all else fails there’s always Cartoon Network.

  • They’re always after me pot o gold…

    The other day in Bend we had a terrific full rainbow fully visible right out our back door. The camera doesn’t have a wide enough angled view to get the whole thing, so I took three pictures and stitched them together:

    May rainbow in Bend

    Click on it for a larger version.

  • Anniversary of my blog. Oh yeah, that other day too.

    Today marks seven years since I started this blog. Seven! Strangely enough, I launched on Earth Day without even knowing it. So when I talk about the significance of "April 22nd" I’m usually not on the same page as everyone else.

  • Random bits on a Friday night

    → My porting of The Brew Site to WordPress worked out remarkably well (minus more fine tuning I still need to do), so sooner or later I’ll get around to porting this site over as well.

    → Not sure what to do with the ebooks page anymore. It’s not going anywhere (I don’t like linkrot), but the Palm eReader platform they were all released for seems to no longer be a relevant format. Seems like Mobipocket is the way to go: it’s supported by all main platforms, it’s an open standard (with development tools, I think), and even Amazon.com has adopted it.

    Of course, I have less time than ever to even think about offering up new ebooks…

    → We went to the school’s Family Fun Night this evening and actually won the drawing for a weekend coast getaway—a condo in or near Newport.

    → Last weekend I opened up some mystery bottles of homebrew that had been in storage for an indeterminate (but fairly long) amount of time.They were actually not at all bad; one was very oxidized and reminiscent of a sherry—no idea what style it was originally—the other was a stout, also oxidized but not as badly. Kind of fun tasting mystery brews like that, so this evening I put four more bottles in the fridge to taste this weekend.

    In this case, I know for sure what at least one of them is: the second beer I ever brewed, a honey wheat ale. Vintage, mid-nineties.

    For reference, I have several bottles of my early batches of beer: one bottle of the very first batch I brewed, a generic amber-ish ale; a bottle or two of the honey wheat; one bottle of the third(?) I brewed, a porter; a bottle of an Oktoberfest (very early also, but I don’t recall exactly when); and one or two bottles of “Capricorn Porter”, a beer brewed with all sorts of things like juniper berries and licorice and such. It dates to ’96 or ’97 I think.

    There are also several other unlabeled bottles as well. I can’t speak for certain how any of these have held up with questionable storage conditions, but who cares? I’m having fun with the adventure. Anyone want to get in on it?

  • Happy Easter

    Kind of a gray, cool day so far, contrary to what the weatherman was predicting. Hope everyone’s having a nice Easter morning, and remember, the Easter Bunny goes back to his old self tomorrow

  • Anathem

    I mentioned awhile back that I received Neal Stephenson’s Anathem for my birthday. This is his latest novel, a monstrous tome that weighs in at nearly 1000 pages, and was released in the latter half of last year. Early reviews seemed really lukewarm to me, in part because of the reveal that Stephenson employs a large invented vocabulary—which often seems to be a crutch or gimmick in the hands of inexperienced writers (not that Stephenson is one)—and in part because it seemed like following up The Baroque Cycle would be really, really hard.

    Well, forget all that. Anathem is a fantastic book, and Stephenson’s best to date. Not only has he matured as a writer (leaps and bounds past his earlier works), he’s put together a tightly-plotted, internally consistent story that’s just dripping with good ideas and has at least one jaw-dropping, mind-blowing concept that, well, becomes a key plot point.

    And, this book actually comes to a solid, satisfying conclusion—one of the major criticisms I’ve had with his earlier works.

    It’s simply a joy to read, and I actually wanted to re-read it almost as soon as I’d finished. That’s a difficult trick to pull off.

  • March 2009’s first post

    And just like that, winter is officially over and spring has arrived. No one’s told the weather, yet, but it’ll figure it out sooner or later.

    I think this past month has been my worst non-blogging streak at this blog to date. Sorry about that. I’ve actually jotted down notes here and there of things to write about but have just been—frankly—too lazy to make the effort to get them down.

    I’ve been porting over my Brew Site blog to run on WordPress, as promised, and it’s been mostly painless. The biggest effort was mapping the database fields and writing the SQL to convert the data from the old tables to the WordPress tables… which turns out to be not that big a deal. Actually, that wasn’t the biggest effort; the biggest effort was creating the theme to more-or-less match what I had before. It’s mostly done, good enough for government work anyway, though I’ll still be twiddling around with it for a while and I already have ideas for something new.

    Next I’ll convert Hack Bend over and finally this blog. Those conversions should go quicker now that I have a pretty good idea of what needs to be done. I’m pretty sure I’m going to open Hack Bend up to multiple contributors. Who wants to write for it? It’s all free, of course, at least until I can figure out how to enable different Google AdSense users.

    That’s all for tonight. Next post: a review of Neal Stephenson’s Anathem.

  • And I don’t even have Monday off

    Depending on how you look at it, my weekend was either eventful or not. It started with me (finally) catching my wife’s cold—this started Friday actually, as I woke up feeling cruddy and was generally run down by the end of the day.

    "It’ll get worse," my wife said. So I was instructed to stay laid-up as much as I could during the weekend, which isn’t really practical when it’s Valentine’s Day and the coffeepot dies.

    And there must be coffee. Right? Right? So I popped over to the nearest coffee stand and grabbed a couple of cups, and later in the morning we made the pilgrimage to Costco for a new coffeepot.

    Our usual Valentine’s tradition is to pick up Papa Murphy’s heart-shaped pizza for dinner and split a bottle of champagne, as a family. No, the kids don’t get any champagne, stop thinking like that. Oh, and chocolate-covered strawberries. This year, my wife and the kids made the strawberries while I napped and sniffled.

    It was a nice evening, even with a cold. It’s one of those colds with sinus pressure, which is no fun, and I seem to have a stiff neck too for some reason. Not sure if I slept on it wrong or what. Beyond that it’s not so much debilitating as annoying.

    Today was a very lazy day, just keeping restful and low-key to speed this cold along. I read a bit, laid down a bit, folded my laundry, that sort of thing. Now it’s 10:30 or so and I’m getting ready to go to bed pretty soon. (Normally it’s around midnight before I go to bed.)

    Working tomorrow. Should be mostly fine, but in case any of my co-workers are reading this, rest assured that I should be past the contagious point and I probably sound worse than I actually feel.