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

"Into to PHP" Milwaukee WordCamp

"Into to PHP" Milwaukee WordCamp

Introduction to PHP for WordPress.

Suzette Franck

July 25, 2014
Tweet

More Decks by Suzette Franck

Other Decks in Technology

Transcript

  1. Intro to PHP
    Suzette Franck
    WordPress Evangelist,
    (mt) Media Temple
    2014 Milwaukee WordCamp
    Foundation Friday, July 25, 2014
    #wcmke @mt_Suzette
    Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple

    View full-size slide

  2. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Suzette Franck with a “ck”
    Twitter:
    @mt_Suzette
    ★WordPress Evangelist @ (mt) Media Temple
    ★Using WordPress since version 2.7 in 2008
    ★20 years of web development experience
    ★Created 200+ WordPress custom themes
    ★Spoke at 20 WordCamps since 2011
    ★WordPress Podcast WPUnicornProject.com
    https://www.youtube.com/user/mediatemple
    ★Reg. Contributor on WPwatercooler.com
    ★Blogs at: suzettefranck.com
    ★Slides: speakerdeck.com/suzettefranck

    View full-size slide

  3. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    ★What is PHP
    ★Tools
    ★Look at PHP Code
    ★Resources
    What We Will Cover

    View full-size slide

  4. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    PHP - What is it?

    View full-size slide

  5. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    PHP - What Is It?
    ★Originated as Personal Home Page Tools,
    now it’s PHP Hypertext Preprocessor
    ★Server-Side Scripting Language (PHP)
    vs. Client-Side Scripting Language (Javascript)
    ★ alongside HTML
    ★Files must have .PHP extension
    ★Needs to be run on a server, outputs HTML
    ★Open Source, free, needs updates occasionally
    ★Runs on Apache and most web servers or OS

    View full-size slide

  6. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    The LAMP Stack
    PHP
    Apache
    Linux
    MySQL
    ★PHP is part of LAMP
    ★PHP processes code into HTML
    ★PHP talks to MySQL Database
    ★PHP evaluates form submissions

    View full-size slide

  7. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    PHP - Tools

    View full-size slide

  8. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    What You’ll Need:
    ★Knowledge of HTML & some CSS
    ★Text Editor
    ★A Modern Browser w/Internet
    ★Google and codex.wordpress.org
    ★Web Host or Local Host running WordPress

    View full-size slide

  9. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    PHP Code Editors

    View full-size slide

  10. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Paid, Free to Try Free, Open Source
    ★Any old text editor will do
    ★Requirements:
    line numbering & syntax highlighting
    Sublime Text 2 (MacOS) Notepad++ (PC)
    PHP Code Editors

    View full-size slide

  11. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Sublime Text 2 (index.php of 2014)

    View full-size slide

  12. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Notepad++ (for PC)

    View full-size slide

  13. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Web Server

    View full-size slide

  14. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    ★PHP 5.2.4 or higher
    ★MySQL 5.0 or higher
    ★Latest Version of WordPress 3.9.1
    Your Web Host Your Computer
    Web Servers

    View full-size slide

  15. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    ServerPress.com

    View full-size slide

  16. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Desktop Server

    View full-size slide

  17. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Where Are The Templates?
    ★On Desktop Server:
    Documents/Websites/sitename.dev/
    wp-content/themes/themename/

    View full-size slide

  18. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Helpful Plugins

    View full-size slide

  19. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Which Template?
    ★“What The File” Free WordPress Plugin

    View full-size slide

  20. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Let’s Look At Code!

    View full-size slide

  21. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Comments in PHP

    Some text.

    Some text.
    ments are fun */ ?>
    Some text.
    // single line
    # single line
    /* multi line com-
    ments are fun*/
    ?>

    View full-size slide

  22. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Anatomy of a Function
    ★PHP Code Opening/Closing Tag
    ★WordPress or PHP Function
    ★Optional Parameters
    ★Line Terminator

    View full-size slide

  23. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Anatomy of a Variable
    ★PHP Code Opening/Closing Tag
    ★Variable Name, starts with $
    ★Operator (Assignment)
    ★Value (String)
    ★Line Terminator

    View full-size slide

  24. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Variables & Data Types

    View full-size slide

  25. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    PHP Data Types
    ★What you can do depends on data type
    ★Variables can change data type
    ★Versatile, but slower than other languages
    ★Strings
    ★Integers and Floating Point Numbers
    ★Boolean (true false)
    ★Arrays (multiple values)
    ★Null

    View full-size slide

  26. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Strings
    ★PHP Code Opening/Closing Tag
    ★Variable Name, starts with $
    ★Operator (Assignment)
    ★Value (String)
    ★Line Terminator

    View full-size slide

  27. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Integers
    ★PHP Code Opening/Closing Tag
    ★Variable Name, starts with $
    ★Operator (Assignment)
    ★Value (Integer)
    ★Line Terminator

    View full-size slide

  28. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Boolean
    ★PHP Code Opening/Closing Tag
    ★Variable Name, starts with $
    ★Operator (Assignment)
    ★Value (boolean)
    ★Line Terminator

    View full-size slide

  29. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Arrays
    ★PHP Code Opening/Closing Tag
    ★Variable Name, starts with $
    ★Operator (Assignment)
    ★Value (array)
    ★Line Terminator

    View full-size slide

  30. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Null
    ★PHP Code Opening/Closing Tag
    ★Variable Name, starts with $
    ★Operator (Assignment)
    ★Value (Null)
    ★Line Terminator

    View full-size slide

  31. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Echo and Print

    View full-size slide

  32. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Echo and Print Statements
    I’d like green eggs. I’d like 3 eggs.
    ★echo() outputs one or more strings.
    ★print() outputs one string and a value of 1
    ★echo() is marginally faster
    ★Both are language constructs
    ★CaSe InSensitive
    ★Both can be used with or without ()
    ★Can include HTML and variables
    ★Single or double quotes

    View full-size slide

  33. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Echo and Print Statements
    $eggs = “green”;
    echo “I’d like $eggs eggs. ”;
    $eggs = 3;
    echo “I’d like $eggs eggs.”;
    ?>
    I’d like green eggs. I’d like 3 eggs.

    View full-size slide

  34. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    All Together Now
    $year = date(‘Y’); // sets year
    echo “Copyright © $year.”;
    ?>
    Copyright © 2014.

    View full-size slide

  35. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Advanced Example
    $year = date(‘Y’); // sets year
    $name = get_bloginfo(‘name’); // sets name
    $email = get_bloginfo(‘admin_email’); // sets email
    echo “Copyright © $year
    by $name.";
    Copyright © 2014 by Intro to PHP.

    View full-size slide

  36. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Operators in PHP
    Arithmetic + - * / %
    Assignment = += -= *= /= %=
    String Concatenation . .=
    Increment/Decrement $x++ $x--
    Comparison == != <> !== > < >= <=
    Logical && and || or xor !

    View full-size slide

  37. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Anatomy of a Statement




    if (have_posts()) {
    // do stuff
    } endif;
    ?>

    View full-size slide

  38. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Anatomy of a The Loop






    View full-size slide

  39. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Resources

    View full-size slide

  40. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Recommended Books
    “WordPress Web Design
    for Dummies”
    by
    Lisa Sabin-Wilson

    View full-size slide

  41. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Recommended Videos
    “WordPress Web Design
    for Dummies”
    by
    Lisa Sabin-Wilson

    View full-size slide

  42. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Recommended Websites
    http://codecademy.com

    View full-size slide

  43. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Recommended Websites
    Google all the things!

    View full-size slide

  44. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Recommended Websites
    http://www.w3schools.com

    View full-size slide

  45. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Recommended Websites
    http://php.net/manual/en/

    View full-size slide

  46. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Recommended Websites
    http://codex.wordpress.org

    View full-size slide

  47. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    In Summary

    View full-size slide

  48. Media Temple // 8520 National Blvd. Culver City, CA 90232 / 877-578-4000 / mediatemple.net / @mt_Suzette © 2014 (mt) Media Temple
    Things to Remember
    ★Follow the script logic flow
    ★Dissect code part-by-part
    ★Look up php functions in google
    ★Variables are different data types
    ★Functions performed based on data types
    ★Have fun and learn!

    View full-size slide

  49. Questions?
    Suzette Franck
    [email protected]
    https://speakerdeck.com/suzettefranck
    HAVE FUN AND LEARN!
    @mt_Suzette
    Follow Me On Twitter!

    View full-size slide