How to create an AJAX call in WordPress step by step

WordPress essentially works thanks to PHP language that gets the requests from users and admins, processes these requests and finally constructs the results as HTML pages, ie, PHP sends to you the pages that you see in the browser. Request, process, results; it’s simple. Sometimes however, you need control some elements of the screen after the HTML page has been sent and displayed: a special message on the screen after a checkbox has been checked, the change of an image depending on a select field, etc. and you don’t want to make a new request again. You want that these little elements change on the screen without repeat the whole process of request, process, results… In these cases you need to use the AJAX technique.

The first historical reference to AJAX technique (Roman Villa at Halicarnassus, 4th century AD)

Beyond this more than dubious historical reference of the previous illustration 🙂 , AJAX is a technology of developement supported by javascript and designed precisely for doing these kind of tasks, ie, to comunicate the client site to the server side silently, without a complete requests, just with the execution of a concrete funcion or module on the server side with a few concrete results. Continue reading…

Creating a Table of Contents for your Pages

WordPress has got the hability to work with nuclear posts and also with posts that can contain other posts, ie, posts with hierarchical structure, the pages. Today we’re going to see how to create a hierarchical list of the second ones, as an index of pages, Table of contents (TOC), etc.

Panzerbaum

As default, WordPress supports two different kinds of elements: posts and pages. The basic difference between them is that the first ones are treated as individual elements and thus, when WordPress displays a collection of them, this will be just a long linear list of elements (like the natural numbers 1, 2, 3, 4, for example) meanwhile the second ones have got a hierachical structure, ie, each element can contain (to point to) elements that have also got hierarchical structure and can contain (to point to) other elements and so on, in consequence, when WordPress displays a collection of them, it should be always presented as a tree and never as a list. Continue reading…

Creating WP help tabs in admin, plugins or themes pages

WordPress has got a help manager very simple, just a couple of functions, so you can easily use it for creating help screen for your own developements. Learn you step by step how the WP help manager works, and how to use it.

Creating WP helps for your plugins and themes

But before beginning to create our own WP help pages, first we should see the internal structure of the WP help manager that, basically has just got two modules. Continue reading…

Using Post Formats with your custom WordPress Post Types

Since versión 3.1, WordPress introduced a new theme feature called Post Formats that, basically, allows us to divide a regular WordPress Post Type in subsets based on the nature of the information that a post includes, ie, you can have regular posts, but you can also have posts that specifically contain a video, or an image, etc. In case of the Post Type post, most of the popular WP themes already includes support for styling its Post Formats but, what can we do for using Post Formats in case of our custom Post Types?

macarons

The proposed method is quite easy and it simply extends the habitually used technic for dealing with Post Formats inside WordPress templates, in other words, we’ll create a refined system for loading the content-{$post_format_slug}.php subtemplates. Continue reading…

How to change the WordPress post updated messages of the edit screen

WordPress posts edit interface has got a good information messages system for all user actions. It doesn’t matter what is the done action, WordPress talks to us: draft saved, post updated, published… Actually, it’s a perfect information system if regulary you only publish posts or sometimes a new page, ie, if you have just got a blog but, when your website has other kinds of information (films, cats, recipies, products…) WordPress keeps saying “post updated” and in fact, you are editing an actor’s profile, or a recipe, or whatever, but not a post… Would not it be awesome that WordPress says “Actor profile updated”, or “Recipe improved” or any message more like the natural language? So, if you don’t want that WordPress talks like a machine, you need use post_updated_messages.

Some examples of WordPress post updated messages on the edit screen

I’m sure that if your website talks about recipes, or actor profiles (whatever that is not a post), you are used to use the WP function register_post_type but probably you don’t know that there is another option that works together with register_post_type that allows us also to change the information messages related with these new kinds of information Continue reading…

Strategies for URL redirection in WordPress front-end pages

I know that is not a common situation but sometimes it’s necessary to redirect the current page to another URL. Inside WordPress back-end is relatively simple but from the WordPress front-end templates that shows the Posts, Pages… It’s a little more complicated.

Change direction

In this article we’ll see some strategies for redirecting the URLs, all of them based in using the WP function template_redirectContinue reading…

Additional Fields to the WordPress Media Uploader

In general, WordPress Media Uploader module has enogh data fields for identifying perfectly any of its elements, images, videos or whatever however, some times, you need not just identifying, for example an image, but to add some information about the exact url source, technical data about the place where it was taken, the people that appears in a photo, etc. In this cases, you need to add some more data fields to the WordPress Media Uploader.

How to add additional fields to the WordPress Media Uploader

In this example, we’re going to suppose that we want to add the name of the place where a photo was taken and, for example, the name of the client for who we are working thus, two additional fields because. By the way, if you was thinking in adding fields to keep the technical information of the photo Continue reading…

Constructing WP themes or plugins that take into account future gender translations (2)

Few days ago I began a serie of articles about how to design a WordPress Theme that facilitates that in the future it is possible to make a translation that takes into account the gender. In the first article I suggested a little technique to mark the Post Type (and for extension Taxonomy) objects including a new property that keeps the gender of the object and that depends on the translation today I’m going to extend this technique also for the labels of the Post type inside the Admin interface.

The #superhero bathroom at  @CommonDesk #fordtx #digitaldallas

As we saw, the core of the first proposal consists of adding one more line inside the array that is used to register any post type Continue reading…

Checkbox fields in WordPress Metaboxes a solution for NULL values

Talking about forms, one of the most common issues is that checkbox fields don’t return any value when they are not checked. We just receive their values -usually TRUE- when they are checked but if they are unchecked they ‘say’ nothing. What can we do?

Checkbox fields in WordPress Metaboxes a solution for NULL values

This behavior of checkboxes fields is not an error, long time ago they was designed in that way (they are silent) however, in most cases,  this behaviour is a problem because the lacking of value doesn’t allow developers to know whether there is not actually a value, or if the value is actually FALSE. There is not difference between NOTHING and FALSE so Continue reading…

How to add a Metabox. A step by step approach. add_meta_box

The WordPress posts edit Tool is not an unique compact module that shows all the boxes that appear on the screen but it’s a set of different little modules –called metaboxes– working together. A little module controls the title, another one controls the visual editor, another one defines the publishing options and actions, another one is for the Post Format… the Categories, the Author’s post, etc. The reason of this modular design is to allow developers to introduce easily new boxes (or remove some ones) in the Edit Screen.

The Edit Screen of Posts and its different Metaboxes

So thanks to this modular design, we can create our metaboxes for adding new functionalities or data to the WordPress Posts Continue reading…