DS106, Feed WordPress, Jim Groom, and Alan Levine!

I feel like I’m time traveling back to the good old days of Mother Blogs.

Jim posted on Mastodon1 about wanting to be able to display the WP excerpt on posts syndicated via Feed WordPress in a Noir-themed #DS106 course he’s teaching. It broke my heart to hear he was doing it by hand. I had a busy couple of days so I didn’t get to this until this morning but I put in a quick 14 minutes2

Alan has some other ways to make this work that I missed but I really wanted to do something WP-related and not AI so . . .

So to make this work, we wanted to only apply it to posts in the “film noir” category and only in archive view. A later addition was to keep the first image in the post.

function ds_noir_chopper($content){
   // Only run filter on single posts in main query

   if (has_category('Tech Noir') || has_category('tech-noir') && is_archive()) {      
      preg_match('/<img.+src=[\'"](?P<src>.+?)[\'"].*>/i', $content, $image);//img? 
      if($image){
         $image = $image[0];//if img, first img
      } else {
         $image = '';
      }
      $content = $image . get_the_excerpt();

      return $content;
   }
   else {
      return $content;
   }
}


add_filter('the_content', 'ds_noir_chopper', 200);


1 Dear tech companies, It’s fine to say post. You don’t need a stupid name for creating content that’s different for every service. Stop it. You’re embarassing everyone.

2 It would have been 5 if I had looked at the Feed WordPress settings earlier.

2 thoughts on “DS106, Feed WordPress, Jim Groom, and Alan Levine!”

  1. This is a clever way, the best part of the stuff is multiple routes to the same end. Yours is better because I forgot the TwentyTwelve does not do mu ch with featured image (I think). But you are right, it was good to dust off some WP chops and poke in the templates.

    But I said nothing about AI, blechhh.

    1. I was just trying to abide by the ancient rule of “never touch the source code in the main files.”

      On another site, I did find it odd that if you’re using the Gute editor the content filter doesn’t work the same way. Poor WP. 🙁

Comments are closed.