Friday night, following a week of deadlines and deadlines and more deadlines, I spent some time working on my website’s code.

Two weeks ago, I wrote that I’d been fighting with the blog theme’s slider; the parent theme, Shoreditch, had a featured content section, but it didn’t slide. Instead, it paged with some controls. The JS library used was certainly capable of “sliding,” and that meant working out how to replace some of the settings when the slider JS loaded.

Last weekend, I spent some time working on code that would display the content I wanted in the featured slider. The Shoreditch slider uses the Featured Content in Jetpack, a collection of WordPress tools, and while the slider was theoretically set up to pull posts (and pages) with a specific tag, in my experience all it pulled was the six most recent posts, regardless of how they were tagged. It seemed to me that if I turned off the Jetpack Featured Content, then I could create a custom loop for the featured slider. I experimented with add_filter calls and remove_filter calls. I tried overwriting Shoreditch’s settings with an add_theme_support call, and I finally discovered remove_theme_support which accomplished exactly what I needed. While that accomplished what I wanted — turning off Jetpack’s Featured Content function, when I tried passing my own custom loop for the featured content area, then I essentially ended up back where I started, with my six most recent posts in the slider. So, I deleted one file from the server (the one that had my custom loop) and commented out the remove_theme_support call in my functions.php file, which put things back to how they had been before I started so I could tackle the problem another day.

After I started looking at the Shoreditch theme again a few weeks ago, I couldn’t understand why I’d given up on it two years ago. It’s an attractive theme, I like how it looks, it’s very readable. I was excited by it in May 2016. What happened? I must have tilted at the windmill of that featured content slider and concluded life was too short to solve its mysteries. Age, wisdom, or stupidity brought me back to it.

This weekend brought me back to the custom loop problem. It took about two hours between Friday and Saturday of coding, testing, and recoding, and at last I got it.

I’m not sure why I hadn’t gotten it to work a week earlier. I suspect I was passing a bad argument to wp_new_query which it didn’t know how to handle so it fell back to most recent posts. The query works by pulling posts with a specific tag (like the Jetpack function did), only unlike the Jetpack function it works. The Jetpack function also hid the tag from readers on the front-end because it’s meaningless to them, and I wanted to do the same thing. I experimented with modifying that function from the Jetpack code, which caused an explosion of PHP errors, so I turned instead to the Googles, and I found the code that I needed on StackExchange.

Now that I have a slider that works, that I can control, I can modify the custom loop into whatever I want. In other words, what I’m currently displaying in the slider — five recent-ish posts that I find interesting — isn’t what I have in mind for the area.

The site is moving incrementally closer to what this ink-stained wretch wants. :)

Leave a Reply

Your email address will not be published. Required fields are marked *