WordPress Widgets: Refactoring, Part 4 Keeping our objects decoupled from one another increases the quality of our code. To start doing so, we can use a Registry.

We’ve implemented a significant amount of changes to the WordPress Widget Boilerplate. If you’ve not been following along, I recommend starting at the beginning of the series and catching up.

If, however, you’ve been following along and you’re also running some of the code quality tools that examine the state of the project, then you’re going to notice a handful of errors in the console.

WordPress Widgets: Refactoring, Part 4

Normally, this is the point where I recommend paying attention to what it shares and then fixing whatever it reports, but we’re not there yet.

For example, some of the errors that our tools are showing right now are based on the fact that we have unused variables. Of course, that’s the case, though, because we haven’t started building a widget.

But there are still a few concrete classes we need to implement.

Continue readingWordPress Widgets: Refactoring, Part 4 Keeping our objects decoupled from one another increases the quality of our code. To start doing so, we can use a Registry.

Back to Twentyseventeen for My Blogging Theme I swapped my blogging theme over to Twentyseventeen. More than a few times, I've been asked "why?"

In the last couple of months, there have been a handful of theme shops that have been acquired by larger hosts. There are obvious benefits to those who run both the shop, the hosting company, and to the customers of the given hosting company.

This also, however, leaves niche theme shops in a unique position. I’m in the process of slowly re-building my business’ site. And in the meantime, I’ve asked the following a question (a few times, actually – yes, I’m quoting myself in a tweet 🤷🏻‍♂️):

The reason I ask, though, is two reasons:

  • for the past half-a-decade, we’ve watched the entire theme landscape change,
  • with the changes that have been introduced into the editor in WordPress 5.0 and what’s coming in the future phases as outlined in the State of the Word, I wonder how this impacts small businesses but bloggers as well.

And the purpose of this post has more to do with the latter point than anything else.

Continue readingBack to Twentyseventeen for My Blogging Theme I swapped my blogging theme over to Twentyseventeen. More than a few times, I’ve been asked “why?”

Custom Archive Templates: A Short Guide Consider this a crash course in creating custom archive templates and all of the functionality that surrounds them.

Whenever you’re working with archive templates in WordPress, posts are typically listed by date in descending order. That is, the most recent posts are listed at the top, and then it goes from there.

Lately, I’ve been working on a few projects that integrate with third-party APIs. These APIs return dates – sometimes two dates, a start date, and an end date – for a given event and customers want to use that information to list posts rather than the date of the post. That is, they want custom archive templates.

It’s not too hard to do this, but before doing so, I think it’s important to give some background information on how the project is built so there’s a bit more context around why, say, a custom query is needed and why you may or may not need to look into pre_get_posts.

I’ll start with a TL;DR first, though. That way, you can get the idea before reading the whole thing.

Continue readingCustom Archive Templates: A Short Guide Consider this a crash course in creating custom archive templates and all of the functionality that surrounds them.

WordPress Widgets: Refactoring, Part 3 Arguably, the biggest problem with the Boilerplate is that everything is encapsulated within a single class. So let's change that with abstract classes.

In terms of updating the WordPress Widget Boilerplate (all of which is tracked in the develop branch), we’ve come a long way in terms of refactoring how it’s organized.

WordPress Widget Boilerplate: The Develop Branch

Thus far, we’ve:

Now we’re ready to start refactoring this code in a much more object-oriented manner.

So if you’ve yet to catch up with the previous posts (any of them, really), I recommend doing so because it’s going to take a little while to bring this up to date. There’s a lot of code to write an explain.

Let’s get started.

Continue readingWordPress Widgets: Refactoring, Part 3 Arguably, the biggest problem with the Boilerplate is that everything is encapsulated within a single class. So let’s change that with abstract classes.

WordPress Pagination: A Simple Utility (And Why) Whenever you're building a web application for someone, there are bound to be nuances in which native WordPress functionality may not work.

When building templates for WordPress, you generally have pagination functions that come from the application itself.

WordPress Pagination: Get Next Post

These incude things like:

And there are a few other posts that give you greater granularity around taxonomies such as get_adjacent_post().

I recommend reading all of the above links because they are useful if you’re building a theme, working with custom post types, or are simply looking for a deeper understanding of some of the common template tags.

If, however, you’re looking for an easy way to write your WordPress pagination utility (which I’ll explain the rationale for momentarily), then the rest of this post will cover exactly that.

Continue readingWordPress Pagination: A Simple Utility (And Why) Whenever you’re building a web application for someone, there are bound to be nuances in which native WordPress functionality may not work.