Categories
Programming

WordPress Loop Error Using get_the_terms

If you get this WordPress Loop Error… “Warning: Invalid argument supplied for foreach() in [filepath].php on line [number]” when you try to loop over terms found using the WordPress function get_the_terms, you may find this information useful. It happens when you have a post that hasn’t been linked to any terms… but it caused by […]

Categories
CMS Programming

WordPress Custom Query Page Size

WordPress normally takes care of queries for you. When it doesn’t, your next port of call is normally WP_Query. After that, you head into nuts-and-bolts mode with a completely custom query using get_posts. When you start taking control over queries, you may hit this common problem with page size. Here is an example of custom […]

Categories
Programming

Signs You Broke the Interface Segregation Principle

I have written quite a lot about how to follow SOLID principles, but one thing that can be useful is examples of where a principle is not being followed. What does your code look like when it wants to tell you something? Here are the signs that you broke the Interface Segregation Principle (ISP). Here […]

Categories
Programming

Your Identity Should Be Immutable and Unconfusable

There are lots of ways to make an identity immutable and unconfusable. I’ll show just a couple, but first the principle behind it. Your identity should be immutable, because you will accumulate lots of threads back to your item that need that identity. If the identity changes, you will be breaking all of the relationships […]

Categories
Visual Studio

Universal Tasks in Visual Studio Code

This is a little trick that allows you to do pretty much whatever you like in a Visual Studio Code task. If you can put it in a batch file, you can do with VSCode. All you need is this “I’ll run a batch file for you” task (and possibly add a problem matcher so […]

Categories
Programming

Useful Apache Mod Rewrite Rules

I recently migrated my website to a different platform. I anticipated that this would require some redirection rules to send people to the correct content on the new website, but I failed to anticipate that number of links to legacy files (like some jQuery plugins and their static HTML example pages). As a result, I […]

Categories
CMS Programming

WordPress Social Sharing Links Without JavaScript

If you, like me, find yourself staring at the network traffic spewing out of your website you will have noticed the JavaScript problem. No matter what plugin you use, it seems to require three or four JavaScript files. Want to show a picture of a cat on your website? You’ll need jQuery, React, and Meteor. […]

Categories
Visual Studio

Custom Tasks In Visual Studio Code

I was asked how to create a custom task in Visual Studio Code. It comes with a bunch of built-in tasks that you can add to the tasks.json file – but what if you need something else… The example below enables PHPLint (in a not-very-sophisticated way) – but the technique would work for anything you […]

Categories
Programming

Writing a Mobile App Using HTML 5

Everyone is keen on writing apps these days. For an organisation, apps are the buzz. For consumers, apps are the convenience. The only problem is that writing apps that target every operating system (and then every version of an operating system that has a wide distribution between versions) can be quite a task. This is […]

Categories
Programming

Dependency Injection in PHP

Dependency Injection solves the problem of dependencies in complex applications. Because we want to re-use our code rather than duplicate it in many places, we end up with more dependencies in our code, but Dependency Injection can ease the pain of dependencies and also make your code easier to test. One of the most popular […]