Exploring PHP Basics

WordPress requires PHP in order to work; therefore, your Web hosting provider must have PHP enabled on your Web server. If you already have WordPress up and running on your Web site, you know PHP is running and working just fine. Currently, the PHP version required for WordPress is version 4.3 or later.

image In the very near future, WordPress will drop support for PHP version 4. When this happens, version 5 will be the only version supported by the WordPress platform. Ask your Web host to upgrade you to PHP version 5 sooner rather than later because most WordPress developers (for plugins, themes, and so on) base their development practices on PHP version 5.

Before you play around with template tags (covered in Book VI) in your WordPress templates or plugin functions, you need to understand what makes up a template tag and why, as well as the correct syntax, or function, for a template tag as it relates to PHP. Additionally, have a look at the WordPress files contained within the download files. Many of the files end with the .php file extension — an extension required for PHP files, which separates them from other file types, such as JavaScript (.js) or CSS (.css).

As we state earlier, WordPress is based in PHP (a scripting language for creating Web pages) and uses PHP commands to pull information from the MySQL database. Every tag begins with the function to start PHP and ends with a function to stop it. In the middle of those two commands lives the request to the database that tells WordPress to grab the data and display it.

A typical template tag, or function, looks like this:

<?php get_info(); ?>

This example tells WordPress to do three things:

  • Start PHP: <?php
  • Use PHP to get information from the MySQL database and deliver it to your blog: get_info();
  • Stop PHP: ?>

In this case, get_info() represents the tag function, which grabs information from the database to deliver it to your blog. The information retrieved depends on what tag function appears between the two PHP commands.

image Every PHP command you start requires a stop command. For every <?php, you must include the closing ?> command somewhere later in the code. PHP commands structured improperly cause ugly errors on your site, and they've been known to send programmers, developers, and hosting providers into loud screaming fits. You find a lot of starting and stopping of PHP throughout the WordPress templates and functions. The process seems as though it would be resource intensive, if not exhaustive, but it really isn't.

image Always, always make sure that the PHP start and stop commands are separated from the function with a single space. You must have a space after <?php and a space before ?> — if not, the PHP function code doesn't work. So make sure that the code looks like this: <?php get_info(); ?> — not like this: <?phpget_info();?>

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.81.58