Comments on WordPress Image Pages, Revisited

Back in January, I posted a solution to a the problem of comment forms on image attachment pages remaining available even after comments on the parent post had closed, based on a solution by Anthony Hortin, of Maddison Designs. I was getting spam from the images on my first gallery page.

The solution I posted back then was to make the include of comments_template() conditional on the parent post’s comments being open. This worked, I stopped getting comments on old images. The code looked like this:

The original fix:

Change this:
<?php comments_template(); ?>
To this:
<?php if (comments_open($post->post_parent)) {
// Only show the Comments Form if the parent post has comments open
} ?>

Unfortunately, the fix has a side effect: comments posted to an image during the “comments open” period also go away when the comments close. At the beginning of the month I posted a picture of some stuff I saw on the Charles that I couldn’t identify; a nice lady answered me, but her answer vanished when the comments closed.

It turns out the comments_template() function also outputs existing comments, so what you really want to do is still include comments_template(), but somehow, tell it comments are closed.

Fortunately, the function that returns the flag that indicates whether comments are open respects a filter, ‘comments_open’, so it became simply a matter of figuring out how to add that filter.

My first attempts to do so crashed. My function that tried to set the flag was trying to call comment_open() with the parent post, and crashed. Then I tried only applying the filter if the parent post’s comments were closed, using a function that simply returns false. It feels kludgy, but it does work.

The Revised Fix:

Change this:
<?php comments_template(); ?>
To this:
function close_image_post_comments() {return false;}

if (!comments_open($post->post_parent)) {
/* Only show the Comments Form if the parent post has comments open
by adding a filter to pass false to comments_open() */

add_filter( 'comments_open', 'close_image_post_comments', 10, 2 );
comments_template(); //bring in the comment output

This feels a little kludgy to me– I’d rather have the decision making in the function rather than the calling code, but it does work, and at this point, I’m not handy enough with PHP to figure out what I was doing wrong in the earlier version of my function.


Quechee Hot Air Balloon Festival


This gallery contains 8 photos.

I visited the Quechee Vermont Hot Air Balloon Festival this weekend with my brother, nephew Matt, and his friend Matthew and his father. We saw “The Glow” opening night, where all the balloons are tied down at dusk, and illuminated by the light of their burners, and had my first balloon ride on Sunday Continue reading

Up a Lazy River

I took advantage of the nice weather on Sunday to spend some more time on the Charles. Earlier in the afternoon, I went in town to go rollerblading for the first time in a long time. I started in Allston, and skated up the bike paths, then crossed over the Anderson bridge to Memorial Drive and skated up to Western Avenue. There was a dragon boat race there, so it was really crowded. It was fun to be back on skates, but boy, was it painful. My legs just aren’t what they used to be.

After getting back to the car, I headed back out to Newton to go kayaking. I’d gone downstream last week, so this week I was determined to go upstream, all the way to the Route 16 dam if I could.

Continue reading

Wascally Wabbits

I’m feeling rather like Elmer Fudd lately. Critters have been eating the bejesus out of my flower garden. And they don’t just eat a few leaves. They leave NOTHING. The morning glories…stripped down to bare stems. My brand new lupines…only a few leaves left. The zinnias….gone.

I’m not sure exactly who the perpetrator is. We saw a woodchuck last year, and this year we’ve seen a small rabbit lurking around the garden. The rabbit is small and cute, but quite brazen.

I decided to try animal repellents. The first one was a pepper based one…no good. Then, last week I picked up one that contained dried fox urine, and sprinkled that around, and put in some replacement zinnias. When I came home last night, the zinnias were nearly gone, and the garden still stank. Great.

I think part of the problem is that there aren’t as many cats around as there used to be. Our cat Mugsy is long gone, and the neighbor across the street who had cats died a couple of years ago, and her cat isn’t there anymore. I first noticed the problem late last year, but now it’s out of hand.

I’m not sure what do do now. I like having flowers in the garden, but I’m restricted to what the animals won’t eat. So far, they haven’t cared for the impatiens, portulaca, roses, or snapdragons. For some reason, of course, they don’t seem to like weeds. I guess I need to decide if I want to care how things look, and then see if I can find some more plants the animals don’t like, or just throw in the towel.

Kayaking the Charles


This gallery contains 11 photos.

Despite the clouds and mist, I went kayaking along the Charles today. I headed downstream against a fairly stiff breeze out of Charles River Canoe and Kayak in Newton. Along the way, I saw a number of swans, a bunch of canadian geese, and the fiberglass animals that one of the homeowners has deployed along the way. Continue reading