Lightning Talk: A short introduction to PHP.
The goal: Learn how to avoid breaking your theme if you edit it. Ben Balter, a J.D./MBA candidate, is a New Media Fellow at the Federal Communications Commission.
Follow him @benbalter.
5. Tags HTML consists of Tags All tags are surrounded by “<“ and “>” e.g., <tag> Tags come in pairs, affecting the content between them e.g., <tag> …. </tag> Tags can also have attributes e.g, <tag attribute=“value”> … </tag>
7. <p> This is an <em>example</em> of a <a href=“http://wordpress.org”>Link to <strong>WordPress<strong></a>, and here is an image <imgsrc=“http:// wordpress.org/logo.jpg” /> </p>
8. New to HTML? Google: HTML, CSS, & js from the Ground Uphttp://code.google.com/edu/submissions/html-css-javascript/ HTML Doghttp://htmldog.com/ W3 Learning Wikihttp://www.w3.org/wiki/HTML/Training W3 Element Wikihttp://www.w3.org/wiki/HTML/Elements
10. Distinguishing PHP from HTML PHP code is wrapped in <?phpand ?> tags. Example: <p> The current time is: <?phpecho date(‘m:s’); ?> </p>
11. Variables A variable is value stored by the server This value can be A number Text Bool (true/false) Other variables (an array) Variables are identified by “$” Variables are set with “=” e.g., $name = “Ben”; echo $name;
12. If Statement An if statement performs an action if a statement is true if ( $color == “red” ) { echo “The ball is red!”; }
13. If Statement If statements can also perform an action if a statement is false. if ( $color == “red” ) { echo “The ball is red!”; } else { echo“The ball is not red”; }
14. While Loop A while loop continues to perform an action while a condition is true While ( $count < 5 ) { echo $count; $count = $count + 1; }
15. Other Loops For for ( $count, $count < 5, $count++ ) { echo $count; } Foreach foreach( $students as $student_name) { echo $student_name; }
16. Functions A function is a pre-set list of commands 700+ built in functions, or you can make your own Functions can take arguments Always followed by parenthesis e.g., strlen( ‘how now brown cow’ );
17. Functions A function is defined… function add( $number1, $number2 ) { $sum = $number1 + $number2; return $sum; }
18. Functions And then called… The sum of 1 and 1 is <?phpechoadd( 1, 1 ); ?>.
19. Final Notes on PHP After every command you need a semicolon Not after If, for, while, foreach, etc. Yes: round( $number, 2 ); No: if ( $number > 5 ) { ; Want to know what a function does? http://php.net/{the name of the function} e.g., http://php.net/strtoupper