Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PHP for WordPress

PHP for WordPress

PHP is a vast language with lots to know, but do we really need to know PHP deeply to start making WordPress themes? In this talk, I’ll go over the basics of PHP to help you get up and running with WordPress development quickly as well as tools to make sure you do learn PHP deeply along the way.

Joe Casabona

July 11, 2016
Tweet

More Decks by Joe Casabona

Other Decks in Programming

Transcript

  1. What is PHP? ◦ Interpreted Programming Language ◦ Compare to

    HTML, CSS, Javascript ◦ Processed by Server ◦ Often used to talk to Databases ◦ Allows for more dynamic content
  2. Anatomy of a PHP Program ◦ PHP files must end

    in .php ◦ PHP code opens with <?php and closes with ?> <?php PHP code lines go here ?>
  3. Variables Variables are a way to store information in order

    to reference it later. Variables can be used to store names, numbers, and other important data. All PHP programs, including WordPress, heavily use variables. $age = 30;
  4. Variables Variables can be letters/symbols (characters), words/phrases (Strings), or numbers

    (integer or decimals/floats) $age = 30; $average = 27.5; $name = “Joe”; $first_letter = ‘J’;
  5. Arrays Arrays are different from other variables. Arrays act as

    
 key -> value pairs. Let’s look at a collection of colors on the next slide. We have an array of size 4 (there are 4 elements), and we can access any one of these by referencing its key, or index. Indexing starts at 0 for arrays, so an array of size 4 will have indexes 0-3.
  6. <?php echo $array[0]; //This will print “red” echo $array[3]; //This

    will print “yellow” ?> Arrays <?php $colors = array( ‘red’, ‘blue’, ‘green’, ‘yellow’ ); ?>
  7. <?php echo $joe[‘name’]; //This will print “Joe Casabona” echo $joe[‘age’];

    //This will print “30” ?> Arrays <?php $joe = array(‘name’ => ‘Joe Casabona’, ‘age’ => 30, ‘profession’ => ‘Web Developer’); ?>
  8. CONTROL STRUCTURES Control Structures are used in PHP to employ

    logic to our code. They are what do the decision making. The most common of these control structures is if statements.
  9. If Statements <?php if ( condition to check ){ ⁄⁄

    code to execute if the condition is true } if ( condition to check ): ⁄⁄ code to execute if the condition is true endif; ?>
  10. If Statements <?php if ( 10 >= 5 ) {

    echo “10 is greater than or equal to 5”; } else { echo “10 is not greater than or equal to 5.”; } ?>
  11. Loops Loops are used to repeat code or continually check

    the condition of a statement. They are a fundamental part of WordPress; the important portion of WordPress code is called “the Loop.” We will look at two types of loops: While Loops and Foreach Loops.
  12. While Loop <?php $i = 0; while( $i <= 10

    ) { echo “<p>$i</p>”; $i = $i + 1; } ?>
  13. Functions Functions are reusable snippets of code that can be

    called multiple times. You can imagine functions as variables for blocks of code. Functions can do one of two things: Return a variable or print something out.
  14. Functions <?php function hello_world() { echo “Hello World”; } ?>

    <?php function is_bigger() { return 10 >= 5; } ?>