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

PHP For Absolute Beginners

PHP For Absolute Beginners

Talk given at the Winnipeg WordPress Meetup on March 6, 2013.

Matt Wiebe

March 06, 2013
Tweet

More Decks by Matt Wiebe

Other Decks in Programming

Transcript

  1. PHP For Absolute
    Beginners
    Matt Wiebe
    @mattwiebe
    wp.mattwie.be
    Design Engineer
    Automattic / WordPress.com

    View Slide

  2. PHP

    View Slide

  3. PHP

    View Slide

  4. View Slide

  5. PHP
    For people who may or may not know what that is.

    View Slide

  6. What is PHP?

    View Slide

  7. What is PHP?
    ★ The thing that makes WordPress work

    View Slide

  8. What is PHP?
    ★ The thing that makes WordPress work
    ★ The thing you should know a little bit
    about if you want to tweak a theme or
    plugin.

    View Slide

  9. What is PHP?
    ★ The thing that makes WordPress work
    ★ The thing you should know a little bit
    about if you want to tweak a theme or
    plugin.
    ★ PHP: Hypertext Preprocessor

    View Slide

  10. View Slide

  11. What is PHP?
    ★ The thing that makes WordPress work
    ★ The thing you should know a little bit
    about if you want to tweak a theme or
    plugin.
    ★ PHP: Hypertext Preprocessor
    ★ The easiest way to get started with
    programming.

    View Slide

  12. What is PHP?
    ★ The thing that makes WordPress work
    ★ The thing you should know a little bit
    about if you want to tweak a theme or
    plugin.
    ★ PHP: Hypertext Preprocessor
    ★ The easiest way to get started with
    programming. (except maybe JavaScript)

    View Slide

  13. What is PHP?





    View Slide

  14. What is PHP?






    View Slide

  15. What is PHP?






    View Slide

  16. What is PHP?






    View Slide

  17. View Slide

  18. Why should I learn PHP?

    View Slide

  19. Why should I learn PHP?
    ★ It’s what makes WordPress sing and dance

    View Slide

  20. Why should I learn PHP?
    ★ It’s what makes WordPress sing and dance
    ★ It’s easy

    View Slide

  21. Why should I learn PHP?
    ★ It’s what makes WordPress sing and dance
    ★ It’s easy
    ★ It’s fun

    View Slide

  22. Why should I learn PHP?
    ★ It’s what makes WordPress sing and dance
    ★ It’s easy
    ★ It’s fun
    ★ It might turn a hobby into a career

    View Slide

  23. THE BASICS

    View Slide

  24. Variables

    View Slide

  25. Variables
    $my_string = 'bar';

    View Slide

  26. Variables
    $my_string = 'bar';

    View Slide

  27. Variables
    $my_string = 'bar';
    // This is a comment. It is ignored.

    View Slide

  28. Variables
    $my_string = 'bar';
    // This is a comment. It is ignored.
    $my_number = 3;

    View Slide

  29. Variables
    $my_string = 'bar';
    // This is a comment. It is ignored.
    $my_number = 3;
    $my_array = array('one', 'two', 'ten');

    View Slide

  30. Variables
    $my_string = 'bar';
    // This is a comment. It is ignored.
    $my_number = 3;
    $my_array = array('one', 'two', 'ten');
    $my_boolean = true;

    View Slide

  31. Variables
    $my_string = 'bar';
    // This is a comment. It is ignored.
    $my_number = 3;
    $my_array = array('one', 'two', 'ten');
    $my_boolean = true;
    /* Now you've seen 4 types of data */

    View Slide

  32. Operations

    View Slide

  33. Operations
    $first_name = 'Matt';
    $last_name = 'Wiebe';

    View Slide

  34. Operations
    $first_name = 'Matt';
    $last_name = 'Wiebe';
    // Concatenation
    $full_name = $first_name . ' ' . $last_name;

    View Slide

  35. Operations
    $my_age = 33;
    $my_nephews_age = 3;

    View Slide

  36. Operations
    $my_age = 33;
    $my_nephews_age = 3;
    // Simple numeric operations: +-*/
    $age_difference = $my_age - $my_nephews_age;

    View Slide

  37. Comparisons

    View Slide

  38. Comparisons
    $my_name = 'Matt';
    $dans_name = 'Dan';
    $my_bosses_name = 'Matt';

    View Slide

  39. Comparisons
    $my_name = 'Matt';
    $dans_name = 'Dan';
    $my_bosses_name = 'Matt';
    $my_name == $dans_name

    View Slide

  40. Comparisons
    $my_name = 'Matt';
    $dans_name = 'Dan';
    $my_bosses_name = 'Matt';
    $my_name == $dans_name;

    View Slide

  41. Comparisons
    $my_name = 'Matt';
    $dans_name = 'Dan';
    $my_bosses_name = 'Matt';
    $my_name == $dans_name;
    // false;

    View Slide

  42. Comparisons
    $my_name = 'Matt';
    $dans_name = 'Dan';
    $my_bosses_name = 'Matt';
    $my_name == $dans_name;
    // false;
    $my_name == $my_bosses_name;

    View Slide

  43. Comparisons
    $my_name = 'Matt';
    $dans_name = 'Dan';
    $my_bosses_name = 'Matt';
    $my_name == $dans_name;
    // false;
    $my_name == $my_bosses_name;
    // true;

    View Slide

  44. Comparisons
    $a == $b // Equal
    $a != $b // Not equal
    $a >= $b // $a greater than or equal to $b
    $a <= $b // $a less than or equal to $b
    $a > $b // $a greater than $b
    $a < $b // $a less than $b

    View Slide

  45. Comparisons
    $a == $b // Equal
    $a != $b // Not equal
    $a >= $b // $a greater than or equal to $b
    $a <= $b // $a less than or equal to $b
    $a > $b // $a greater than $b
    $a < $b // $a less than $b
    /* There are a lot more but
    that’s all we’ll cover now. */

    View Slide

  46. Using Comparisons
    if ( $a == $b ) {
    }

    View Slide

  47. Using Comparisons
    if ( $a == $b ) {
    }

    View Slide

  48. Using Comparisons
    if ( $a == $b ) {
    // do something
    }

    View Slide

  49. Using Comparisons
    if ( $a == $b ) {
    // do something
    }
    else {
    }

    View Slide

  50. Using Comparisons
    if ( $a == $b ) {
    // do something
    }
    else {
    // do something else
    }

    View Slide

  51. Functions

    View Slide

  52. Functions

    View Slide

  53. View Slide

  54. Functions
    $name = 'Matt Wiebe';

    View Slide

  55. Functions
    $name = 'Matt Wiebe';
    $fun = str_replace( 'Matt', 'Jerk', $name );

    View Slide

  56. Functions
    $name = 'Matt Wiebe';
    $fun = str_replace( 'Matt', 'Jerk', $name );

    View Slide

  57. Functions
    $name = 'Matt Wiebe';
    $fun = str_replace( 'Matt', 'Jerk', $name );

    View Slide

  58. Functions
    $name = 'Matt Wiebe';
    $fun = str_replace( 'Matt', 'Jerk', $name );

    View Slide

  59. Functions
    $name = 'Matt Wiebe';
    $fun = str_replace( 'Matt', 'Jerk', $name );

    View Slide

  60. Functions
    $name = 'Matt Wiebe';
    $fun = str_replace( 'Matt', 'Jerk', $name );
    echo $fun;
    // 'Jerk Wiebe'

    View Slide

  61. WordPress Functions

    View Slide

  62. WordPress Functions
    In WordPress, template tags are
    PHP functions.

    View Slide

  63. View Slide

  64. WordPress Functions
    Home

    View Slide

  65. WordPress Functions
    Home

    View Slide

  66. WordPress Functions
    Home








    View Slide

  67. WordPress Functions
    Home








    View Slide

  68. WordPress Functions
    Home








    View Slide

  69. WordPress Functions
    Home








    View Slide

  70. WordPress Functions
    Home








    View Slide

  71. WordPress Functions
    ★ Read the Codex:

    View Slide

  72. WordPress Functions
    ★ Read the Codex:
    ★ codex.wordpress.org

    View Slide

  73. WordPress Functions
    ★ Read the Codex:
    ★ codex.wordpress.org
    ★ Learn the template hierarchy

    View Slide

  74. WordPress Functions
    ★ Read the Codex:
    ★ codex.wordpress.org
    ★ Learn the template hierarchy
    ★ codex.wordpress.org/Template_Hierarchy

    View Slide

  75. WordPress Functions
    ★ Read the Codex:
    ★ codex.wordpress.org
    ★ Learn the template hierarchy
    ★ codex.wordpress.org/Template_Hierarchy
    ★ Make a child theme to hack on

    View Slide

  76. WordPress Functions
    ★ Read the Codex:
    ★ codex.wordpress.org
    ★ Learn the template hierarchy
    ★ codex.wordpress.org/Template_Hierarchy
    ★ Make a child theme to hack on
    ★ codex.wordpress.org/Child_Themes

    View Slide

  77. WordPress Functions
    ★ Learn the template tags (functions):

    View Slide

  78. WordPress Functions
    ★ Learn the template tags (functions):
    ★ codex.wordpress.org/Template_Tags

    View Slide

  79. View Slide

  80. ?>
    Matt Wiebe
    @mattwiebe
    wp.mattwie.be
    Design Engineer
    Automattic / WordPress.com

    View Slide