PHP For Absolute Beginners

PHP For Absolute Beginners

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

3f7cda86b0d471afad79a0b5423d1677?s=128

Matt Wiebe

March 06, 2013
Tweet

Transcript

  1. PHP For Absolute Beginners Matt Wiebe @mattwiebe wp.mattwie.be Design Engineer

    Automattic / WordPress.com
  2. PHP

  3. PHP

  4. None
  5. PHP For people who may or may not know what

    that is.
  6. What is PHP?

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

  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.
  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
  10. None
  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.
  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)
  13. What is PHP? <!DOCTYPE html> <html> <body> </body> </html>

  14. What is PHP? <!DOCTYPE html> <html> <body> <?php echo "Hello

    World"; ?> </body> </html>
  15. What is PHP? <!DOCTYPE html> <html> <body> <?php echo "Hello

    World"; ?> </body> </html>
  16. What is PHP? <!DOCTYPE html> <html> <body> <?php echo "Hello

    World"; ?> </body> </html>
  17. None
  18. Why should I learn PHP?

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

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

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

    sing and dance ★ It’s easy ★ It’s fun
  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
  23. THE BASICS

  24. Variables

  25. Variables $my_string = 'bar';

  26. Variables $my_string = 'bar';

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

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

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

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

    is ignored. $my_number = 3; $my_array = array('one', 'two', 'ten'); $my_boolean = true;
  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 */
  32. Operations

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

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

    = $first_name . ' ' . $last_name;
  35. Operations $my_age = 33; $my_nephews_age = 3;

  36. Operations $my_age = 33; $my_nephews_age = 3; // Simple numeric

    operations: +-*/ $age_difference = $my_age - $my_nephews_age;
  37. Comparisons

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

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

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

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

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

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

    $my_name == $dans_name; // false; $my_name == $my_bosses_name; // true;
  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
  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. */
  46. Using Comparisons if ( $a == $b ) { }

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

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

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

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

    do something } else { // do something else }
  51. Functions

  52. Functions

  53. None
  54. Functions $name = 'Matt Wiebe';

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

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

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

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

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

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

    $name ); echo $fun; // 'Jerk Wiebe'
  61. WordPress Functions

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

  63. None
  64. WordPress Functions <a href="<?php echo home_url(); ?>">Home</a>

  65. WordPress Functions <a href="<?php echo home_url(); ?>">Home</a>

  66. WordPress Functions <a href="<?php echo home_url(); ?>">Home</a> <article> <h1> <a

    href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a> </h1> <?php the_content(); ?> </article>
  67. WordPress Functions <a href="<?php echo home_url(); ?>">Home</a> <article> <h1> <a

    href="<?php the_permalink(); ?>"> <?php the_title(); ?> </a> </h1> <?php the_content(); ?> </article>
  68. WordPress Functions <a href="<?php echo home_url(); ?>">Home</a> <article> <h1> <a

    href="<?php the_permalink(); ?>"> <?php echo the_title(); ?> </a> </h1> <?php the_content(); ?> </article>
  69. WordPress Functions <a href="<?php echo home_url(); ?>">Home</a> <article> <h1> <a

    href="<?php the_permalink(); ?>"> <?php echo the_title(); ?> </a> </h1> <?php the_content(); ?> </article>
  70. WordPress Functions <a href="<?php echo home_url(); ?>">Home</a> <article> <h1> <a

    href="<?php the_permalink(); ?>"> <?php echo get_the_title(); ?> </a> </h1> <?php the_content(); ?> </article>
  71. WordPress Functions ★ Read the Codex:

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

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

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

    the template hierarchy ★ codex.wordpress.org/Template_Hierarchy
  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
  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
  77. WordPress Functions ★ Learn the template tags (functions):

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

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