5.1: Building and Modifying Themes

5.0 Programming For WordPress

  • WordPress developers use PHP and JavaScript to build powerful and highly customized WordPress Websites. We will be investigating both of these programming languages in this section.

5.1 PHP Programming

  • WordPress itself was built and continues to evolve with programs and functions written in PHP

  • With a good understanding of PHP and the myriad functions contained in the WordPress library we are able to turn an simple, rather ordinary Website into a highly customized site.

  • Before we start coding let's set up some data that we can work with

  • Open MAMP and click "Start Servers"

Figure 5.1.1

  • Once the Apache Server and MySQL Server checkboxes are filled you can minimize this MAMP window. The filled checkboxes tell us the server has started

  • In your browser address box enter: http://localhost:8888 (note that the port shown here as 8888 may be different with your MAMP installation.

  • Now navigate your folders to the root of your child theme. It should look something like this:

Figure 5.1.2

  • Open the index.php file with your editor and delete all of its contents.

  • Most employers will have standards for documenting your code. This is done using comments

  • Comments are enclosed between a forward slash and asterisk like this /* I am a comment */

  • Enter some comments into your index.php file similar to comments shown in figure 4.1.3 below.

  • PHP language scripting is enclosed within a special sequence of characters like this: <?php echo "this text generated by php" ?>

  • Add an open and a close php tags as shown in figure 4.1.3 below

  • Add a php statement between the open and close php tags like the one below in figure 4.1.3 and save the file.

Note that the PHP echo command used in this example is one of the ways we can push values to the computer screen.

Figure 5.1.3 Open your browser and navigate to the blog page of your Diamond Dog Entertainment siteYou should see the message "this is a php statement" in the browser viewing window

Figure 5.1.4 Now we will take some early steps toward working with PHP for your WordPress site.What you code in this next section will not be used in the final site and it won't look like much at this point but you will definitely use these concepts as we build the Diamond Dogs Entertainment site.

Last updated