Tag Archives: arrays

These are the properties of a WordPress post. Source: WordPress Codex, XML-RPC WordPress API/Posts

Using The WordPress XML-RPC API With PHP: The Post Model’s Properties

Part 4 in a series on working with the WordPress XML-RPC API with PHP.

Previously I discussed the reasons for creating a data model (aka a class), that looks like a WordPress post, in order to streamline and simplify working with the WordPress XML-RPC API.

In this post, we’ll create the properties, or data, that goes into that model. This will help us make heads and tails out of what we need to send to the XML-RPC API, and what we’ll get back, when working with posts.
Continue reading

Using WordPress XML-RPC With PHP: Introduction

Part 1 in a series on working with the WordPress XML-RPC API with PHP.

Lately I’ve had cause to work with WordPress’s implementation of XML-RPC, which is basically a kind of SOAP service that lets you view, add, edit and remove content from outside of your WordPress install.

XML-RPC has been part of WordPress since its initial public release some 11 years ago, but is usually scorned as little more than an efficient attack vector. Which is a fair assessment; few end users need the ability to remotely publish content.

But over the years — especially the last two — as WordPress has melded into a turnkey content management solution, XML-RPC has been improved, both in terms of its base security and its functionality.

Today, it’s perfectly positioned to be a great way to manage content from outside of WordPress itself; that is, to bring in content from third-party systems (which is how I am doing it) to automating virtually any task you have that involves the actual content of your blog.

Except …
Continue reading

How To Increment A Counter In MySQL Based On A Radio Button Click

Asked recently on Formspring:

how to increment count in database on clicking radio button

There are a few ways to go about this. I’ll demonstrate two: a traditional, PHP / MySQL only, postback approach, and a jQuery version that uses AJAX to asynchronously record and update the counts.

Just to be clear: In order to complete this solution, we have to use both JavaScript and a server-side scripting language. We use JavaScript to intercept the user clicking the radio button, but process the fact that the button was clicked on the server.

Also, for the purpose of this tutorial, I’ll assume that the radio button involved is part of a group. That is, we have several radio buttons, all with the same name, but different values, e.g.:

<form id="myform" name="myform" method="post">
	<p>Select a color:</p>
	<label id="l_red"><input type="radio" id="r_red" name="color_name" value="red" />Red</label> (<label id="c_red">0</label>) | 
	<label id="l_green"><input type="radio" id="r_green" name="color_name" value="green" />Green</label> (<label id="c_green">0</label>) | 
	<label id="l_blue"><input type="radio" id="r_blue" name="color_name" value="blue" />Blue</label> (<label id="c_blue">0</label>) | 
	<label id="l_black"><input type="radio" id="r_black" name="color_name" value="black" />Black</label> (<label id="c_black">0</label>)
</form>

Continue reading

Preloading Images With JavaScript

Anne Hathaway

Anne Hathaway photo by Brian Smith

In my recent travels through old blog posts, I’ve noticed a number of occasions where I’ve discussed how to preload images.

Almost all those examples are stupid or just plain wrong. For that, you have my apologies, and I aim to rectify those mistakes with this post.

First, why would we want to preload an image? Simply put, we intend to show it later on our Web page — either as a result of a mouseover, or a click, or some other sort of Document Object Model (DOM) event.

For example, maybe we want to mouseover a series of thumbnails, and show a larger version of that image in the same place.

Rather than making the end user wait for a new image to load as a result of doing something on a Web page, it makes sense to load the image we intend to show in advance, so it will display almost instantaneously as a result of an event.

I’ll first show why two of my previous methods for preloading images are wrong or dumb, then describe two correct ways to preload images: via basic JavaScript and via jQuery.

The lovely Anne Hathaway will be our model.
Continue reading