How I Learned to Stop Worrying and Love the Code<br />Benjamin J. Balter<br />webBen.Balter.com<br />emailBen@Balter.com<b...
In Five Minutes You Will Know<br />HTML & PHP<br />(well, just enough knowledge to be dangerous)<br />
HTML<br />
Tags<br />HTML consists of Tags<br />All tags are surrounded by “<“ and “>”<br />e.g., <tag><br />Tags come in pairs, affe...
Common Tags<br />Bold: <strong> … </strong><br />Italic: <em> … </em><br />Paragraph: <p> … </p><br />Heading: <h1> … </h1...
<p><br />	This is an <em>example</em> of a <br /><a href=“http://wordpress.org”>Link to 	<strong>WordPress<strong></a>,<br...
New to HTML?<br />Google: HTML, CSS, & js from the Ground Uphttp://code.google.com/edu/submissions/html-css-javascript/<br...
In the Beginning There was…<br /><?php<br />
Distinguishing PHP from HTML<br />PHP code is wrapped in <?phpand ?> tags. Example:<br />		<p><br />			The current time is...
Variables<br />A variable is value stored by the server<br />This value can be<br />A number<br />Text<br />Bool (true/fal...
If Statement<br />An if statement performs an action if a statement is true<br />if ( $color == “red” ) {<br />echo “The b...
If Statement<br />If statements can also perform an action if a statement is false. <br />if ( $color == “red” ) {<br />ec...
While Loop<br />A while loop continues to perform an action while a condition is true<br />While ( $count < 5 ) {<br />ech...
Other Loops<br />For<br />for ( $count, $count < 5, $count++ ) {<br />echo $count;<br />}<br />Foreach<br />foreach( $stud...
Functions<br />A function is a pre-set list of commands<br />700+ built in functions, or you can make your own<br />Functi...
Functions<br />A function is defined…<br />function add( $number1, $number2 ) {<br />		$sum = $number1 + $number2;<br />re...
Functions<br />And then called…<br />	The sum of 1 and 1 is <br /><?phpechoadd( 1, 1 ); ?>.<br />
Final Notes on PHP<br />After every command you need a semicolon<br />Not after If, for, while, foreach, etc.<br />Yes: ro...
Putting It All Together: loop-page.php<br /><?phpif ( have_posts() ) while ( have_posts() ) : the_post(); ?><br /><div id=...
Putting It All Together (Cont.)<br /><div class="entry-content"><br /><?phpthe_content(); ?><br />	<?phpwp_link_pages( arr...
Tools & Resources<br />
Tools<br />Text Editor<br />Whatever came with your computer<br />Notepad++ (Windows)<br />TextWrangler, Coda (Mac)<br />F...
Benjamin J. Balter<br /> webBen.Balter.com<br />emailBen@Balter.com<br />twitter 	@BenBalter<br />
Upcoming SlideShare
Loading in...5
×

How I Learned to Stop Worrying and Love the Code

960

Published on

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.

Published in: Technology
1 Comment
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total Views
960
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
3
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide

How I Learned to Stop Worrying and Love the Code

  1. 1. How I Learned to Stop Worrying and Love the Code<br />Benjamin J. Balter<br />webBen.Balter.com<br />emailBen@Balter.com<br />twitter @BenBalter<br />
  2. 2. In Five Minutes You Will Know<br />HTML & PHP<br />(well, just enough knowledge to be dangerous)<br />
  3. 3.
  4. 4. HTML<br />
  5. 5. Tags<br />HTML consists of Tags<br />All tags are surrounded by “<“ and “>”<br />e.g., <tag><br />Tags come in pairs, affecting the content between them<br />e.g., <tag> …. </tag><br />Tags can also have attributes<br />e.g, <tag attribute=“value”> … </tag><br />
  6. 6. Common Tags<br />Bold: <strong> … </strong><br />Italic: <em> … </em><br />Paragraph: <p> … </p><br />Heading: <h1> … </h1>, <h2> … </h2><br />Link: <a href=“http://…”> … </a><br />Image: <imgsrc=“http://…” /><br />Full List: w3schools.com<br />
  7. 7. <p><br /> This is an <em>example</em> of a <br /><a href=“http://wordpress.org”>Link to <strong>WordPress<strong></a>,<br /> and here is an image <imgsrc=“http:// wordpress.org/logo.jpg” /><br /></p><br />
  8. 8. New to HTML?<br />Google: HTML, CSS, & js from the Ground Uphttp://code.google.com/edu/submissions/html-css-javascript/<br />HTML Doghttp://htmldog.com/<br />W3 Learning Wikihttp://www.w3.org/wiki/HTML/Training<br />W3 Element Wikihttp://www.w3.org/wiki/HTML/Elements<br />
  9. 9. In the Beginning There was…<br /><?php<br />
  10. 10. Distinguishing PHP from HTML<br />PHP code is wrapped in <?phpand ?> tags. Example:<br /> <p><br /> The current time is: <br /><?phpecho date(‘m:s’); ?><br /> </p><br />
  11. 11. Variables<br />A variable is value stored by the server<br />This value can be<br />A number<br />Text<br />Bool (true/false)<br />Other variables (an array)<br />Variables are identified by “$”<br />Variables are set with “=”<br />e.g., $name = “Ben”;<br />echo $name;<br />
  12. 12. If Statement<br />An if statement performs an action if a statement is true<br />if ( $color == “red” ) {<br />echo “The ball is red!”;<br /> }<br />
  13. 13. If Statement<br />If statements can also perform an action if a statement is false. <br />if ( $color == “red” ) {<br />echo “The ball is red!”;<br /> } else {<br />echo“The ball is not red”;<br /> }<br />
  14. 14. While Loop<br />A while loop continues to perform an action while a condition is true<br />While ( $count < 5 ) {<br />echo $count;<br /> $count = $count + 1;<br /> }<br />
  15. 15. Other Loops<br />For<br />for ( $count, $count < 5, $count++ ) {<br />echo $count;<br />}<br />Foreach<br />foreach( $students as $student_name) {<br />echo $student_name;<br /> }<br />
  16. 16. Functions<br />A function is a pre-set list of commands<br />700+ built in functions, or you can make your own<br />Functions can take arguments<br />Always followed by parenthesis<br />e.g., strlen( ‘how now brown cow’ );<br />
  17. 17. Functions<br />A function is defined…<br />function add( $number1, $number2 ) {<br /> $sum = $number1 + $number2;<br />return $sum;<br /> }<br />
  18. 18. Functions<br />And then called…<br /> The sum of 1 and 1 is <br /><?phpechoadd( 1, 1 ); ?>.<br />
  19. 19. Final Notes on PHP<br />After every command you need a semicolon<br />Not after If, for, while, foreach, etc.<br />Yes: round( $number, 2 );<br />No: if ( $number > 5 ) { ;<br />Want to know what a function does?<br />http://php.net/{the name of the function}<br />e.g., http://php.net/strtoupper<br />
  20. 20. Putting It All Together: loop-page.php<br /><?phpif ( have_posts() ) while ( have_posts() ) : the_post(); ?><br /><div id="post-<?phpthe_ID(); ?>" <?phppost_class(); ?>><br /> <?phpif ( is_front_page() ) { ?><br /><h2 class="entry-title"><br /> <?phpthe_title(); ?><br /></h2><br /> <?php } else { ?><br /><h1 class="entry-title"><br /> <?phpthe_title(); ?><br /></h1><br /> <?php } ?> <br />
  21. 21. Putting It All Together (Cont.)<br /><div class="entry-content"><br /><?phpthe_content(); ?><br /> <?phpwp_link_pages( array( 'before' => <br /> '<div class="page-link">' . __( 'Pages:', 'twentyten' ), <br /> 'after' => '</div>' ) ); ?><br /><?phpedit_post_link( __( 'Edit', 'twentyten' ), <br /> '<span class="edit-link">', '</span>' ); ?><br /> </div><!-- .entry-content --><br /> </div><!-- #post-## --><br /> <?phpcomments_template( '', true ); ?><br /><?phpendwhile; // end of the loop. ?><br />
  22. 22. Tools & Resources<br />
  23. 23. Tools<br />Text Editor<br />Whatever came with your computer<br />Notepad++ (Windows)<br />TextWrangler, Coda (Mac)<br />FTP Client (to connect to server)<br />WinSCP, Notepad++ (Windows)<br />CyberDuck, Coda (Mac)<br />WordPress<br />Define( WP_DEBUG, true); in wp-config.php<br />Debug bar plugin<br />WordPress Codex<br />
  24. 24. Benjamin J. Balter<br /> webBen.Balter.com<br />emailBen@Balter.com<br />twitter @BenBalter<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×