Object-Oriented PHP With Classes and Objects

In this article, we're going to explore the basics of object-oriented programming using PHP classes. We'll start with an introduction to classes and objects, and we'll discuss a couple of advanced concepts like inheritance and polymorphism in the latter half of this article. What Is Object-Oriented Programming (OOP)? Object-oriented programming, commonly referred to as OOP, is an approach which helps you to develop complex applications in a way that's easily maintainable and scalable over the long term. In the world of OOP  (to create object in PHP), real-world entities such as Person, Car, or Animal are treated as objects. In object-oriented programming, you interact...

Your First WordPress Plugin: Simple Optimization

WordPress is the largest blogging platform available on the internet today; and with the official release of version three just around the corner, it's only going to get bigger. As such, over the next few self-contained tuts, we're going to learn the ins and outs of WordPress plugin development, starting with the creation of our first simple plugin, "Simple Optimization." Step 0 Before we Begin This tutorial is going to assume that you have at least a beginner's understanding of PHP and the WordPress syntax. Though we'll be covering everything, some knowledge beforehand will help you grasp the concepts much more...

Create WordPress Plugins With OOP Techniques

Object-oriented code, among other things, can help organize and add reusability to your code. In this tutorial, I will teach you the basics of writing a WordPress plugin using object-oriented techniques. We'll be using Dribbble's API as an example for this tutorial. Ready? What We're Going to Learn Benefits of using OOP for WordPress plugins How to set up a shortcode How to set up a template tag How to enable shortcode in WordPress widgets Real-world example using Dribbble's API By the way, if this sounds too advanced and you're just looking for some ready-made plugins that you can download...

Add an Expiry Date to WordPress Posts

I run a few sites which include notices and important information in a banner on their home page. I tend to use a custom post type for this, adding my banners and displaying them where I need to in my theme. (If you want to do something similar, it's explained in this tutorial.) But invariably my banners have an expiry date. They might contain information about an upcoming event or a vacancy, for example. Once the event has passed or the vacancy has been filled, I have to go into the site and manually trash the post. It would be so...

Add an Automatic ‘Featured Image’ to Blog Posts Based on Category

Using featured images in post archives is a common feature of themes, but sometimes you might want to use featured images a bit differently. Occasionally I've worked on sites where the images to be displayed relate to the category a post is in and not to the post itself. Instead of adding the same featured image to every post in each category, it would be much simpler if I could just assign the category to each of my images, and then display the featured image for the category with the post. Examples of when you might want to do this...

Add a Custom Column in Posts and Custom Post Types Admin Screen

In this tutorial we will see how to add a new column to the WordPress Posts management screen and in this column we will show the Featured Image of each Post. This new column will also be added in the management screen of any active Custom Post Type. Step 1 Activate Featured Images In this tutorial we will use the functions.php file available in our active theme directory. If the file is not present, you can create a new one with the following contents: First of all, check if the Featured Image is available on the Add New Post page: If you don't see the Featured...

Creating an Upcoming Events Plugin in WordPress: Introduction

WordPress is not just a blogging platform anymore, but can be used to develop complex web applications for many purposes. WordPress provides variety of APIs, thus allowing us to develop further on its base. We can extend WordPress to meet our needs using the Plugins API. With this powerful API we can develop solutions meeting our needs for near endless scenarios; therefore, to become a master of WordPress, once has to master its APIs. In this series, we will look at the WordPress Plugins API as well as Widget API and how we can use them to develop solutions specific...

A Guide to Overriding Parent Theme Functions in Your Child Theme

If you've had any experience working with parent and child themes in WordPress, you'll know that the template files in your child theme override those in your parent theme. For example, if your parent theme has a page.php file and you create a new one in your child theme, WordPress will use the one in the child theme when displaying pages. You might think that functions would work in the same way: create a new function in your child theme's functions.php file with the same name as one in the parent theme, and it'll take precedence. Unfortunately, it isn't as simple as this. In...

How to Create Custom WordPress Write/Meta Boxes

Creating meta boxes is a crucial part of WordPress theme/plugin development. It's a way to add an appealing editor to the post screen and avoids forcing users to rely on custom fields. If you've ever created a custom post type in WordPress, you've probably wanted to add some sort of additional data to it. Sure, you could use custom fields, but that's ugly. Getting started with custom meta boxes is easy, so let's dive in! What Are Custom Meta Boxes? A custom meta (or write) box is incredibly simple in theory. It allows you to add a custom piece of data to a post or...