20120722 word press

Post on 08-May-2015

666 views 0 download

Transcript of 20120722 word press

FOR ALL KINDS OF PURPOSES

Programming Background for WordPress

Barnabas KimMobile Augmented Reality

July 22, 2012

REV 3: WW22 | 2011

FOR ALL KINDS OF PURPOSES2Intel Corporation

Mobile Augmented Reality

TABLE OF CONTENTS

WE WILL COVER THE BELOW TOPICS TODAY:

• TOPICS1. Preliminaries2. PHP Tutorial for WordPress3. Anatomy of a WordPress theme

July 22, 2012

FOR ALL KINDS OF PURPOSES Intel Corporation

Topic #1:Preliminaries

3

FOR ALL KINDS OF PURPOSES4Intel Corporation

Mobile Augmented Reality

BASIC CONCEPTS: Web Server Stacks

July 22, 2012

HARDWARE

SOFTWARE

SERVER (or PC)

Operating System (Linux / MacOS / Windows)

Apache Web Server (80) MySQL DB Server (3306)

PHP Parser (Server-side script)

Web Applications(WordPress)

FOR ALL KINDS OF PURPOSES5Intel Corporation

Mobile Augmented Reality

BASIC CONCEPTS: Client↔Server Interaction

July 22, 2012

1. USER: Request URL (via Web Browser)http://wordpress.org

Apache Web Server (80)

Port: 80Host: wordpress.orgIP: 72.233.56.139URL: /

2. Web Server:Response to the requested URLbased on the setting

/home/wordpress/index.php

3. Read and parse the corresponding file

<html><body><div><?php echo “Wordpress”; ?></div></body></html>

<html><body><div>Wordpress</div></body></html>

4. Print the parsed webpage to the browser

Parse

FOR ALL KINDS OF PURPOSES Intel Corporation

Topic #2:PHP Tutorial for WordPress

6

FOR ALL KINDS OF PURPOSES7Intel Corporation

Mobile Augmented Reality

PHP Tutorial for WordPress

• Contents1. What is PHP? PHP vs. HTML2. How do I insert PHP into a web page?3. Variables4. Conditional statements5. Functions

• Reference– http://adambrown.info/b/widgets/easy-php-tutorial-for-wordpress-

users/

July 22, 2012

FOR ALL KINDS OF PURPOSES8Intel Corporation

Mobile Augmented Reality

PHP Tutorial: 1. What is PHP?

• PHP is Server-side script that makes webpage dynamic.

– Static Web page:

– <p>Today is July 22, 2012</p>

– Dynamic Web page:

– <p>Today is <?php echo date(“F j, Y”); ?>

• PHP code does not get sent to the browser, only the HTML that the PHP parser produces.

July 22, 2012

FOR ALL KINDS OF PURPOSES9Intel Corporation

Mobile Augmented Reality

PHP Tutorial: 2. How do I insert PHP into web page?

• PHP codes should be wrapped by <?php … ?> or <? … ?>

– <div>

– <?php

– $var1 = “Hi, WordPress!”; ⁄⁄ two slashes indicate that everything until the end of the line is a comment

– $var2 = “Hi, Man!”;

– /*

– if your comment spans more than one line,

– like this one, use the slash-asterisk format.

– */

– echo $var1; echo “<br/>”;

– echo $var2; echo “<br/>”;

– ?>

– </div>

July 22, 2012

FOR ALL KINDS OF PURPOSES10Intel Corporation

Mobile Augmented Reality

PHP Tutorial: 3. Variables (1/2)

• A variable is always written with $ at the beginning, and the alphabetical words from the second letter.

• For string values, it should be enclosed with ‘ (apostrophe) or “ (quotes). Every line should be ends with ; (semicolon)

– <?php

– $nDate = 22;

– $myFirstName = “Barnabas”;

– $myFamilyName = ‘Kim’;

– ?>

• Note that,

1. Case sensitive:

– e.g. $myname, $myName are totally different variables.

2. Does not allow to starts with ‘number’ or ‘special character’:

– e.g. $_myname (X), $1234 (X) are not correct.

July 22, 2012

FOR ALL KINDS OF PURPOSES11Intel Corporation

Mobile Augmented Reality

PHP Tutorial: 3. Variables (2/2)

• To display the contents of a variable on the web page, just use echo. You should allocate variables before using echo.

– <?php

– $nDate = 22;

– echo $nDate;

– ?>

• To append something to an existing variable, use . (dot)

– <?php

– $date = 22;

– $month = “July”;

– $year = 2012;

– $strToday = $month.” ”.$date.”, ”.$year;

– ?>

July 22, 2012

FOR ALL KINDS OF PURPOSES12Intel Corporation

Mobile Augmented Reality

PHP Tutorial: 4. Conditional Statements

• Conditional statements checks condition before proceeding or to repeat a block of code multiple times.

– Control statements:

– if .. elseif .. else

– <?php

– $var = 10;

– if($var == 5){

– echo “5 in the variable”;

– }else if($var > 5){

– echo “The variable has the value bigger than 5”;

– }else{

– echo “The variable has the value smaller than 5”;

– }

– ?>

– Loop: while, for, foreach (These are not covered in this tutorial.)

July 22, 2012

FOR ALL KINDS OF PURPOSES13Intel Corporation

Mobile Augmented Reality

PHP Tutorial: 5. Functions (1/2)

• If a function is called (sometimes with input parameters), the function returns values (sometimes not).

– <?php

– echo date(“Y-m-d”);

– echo time();

– include(“header.php”);

– ?>

• A function can be regarded as a variable.

– <?php

– if(date(“Y-m-d”) == “2012-07-22”){

– echo “Today is 2012-07-22”;

– }

– ?>

July 22, 2012

FOR ALL KINDS OF PURPOSES14Intel Corporation

Mobile Augmented Reality

PHP Tutorial: 5. Functions (2/2)

There are two types of functions

1. Internal (built-in) functions:

– String, Variable, Image Functions, …

– Function Reference: http://www.php.net/manual/en/funcref.php

– e.g.

– <?php

– $var1 = “Hello!”;

– echo str_replace(“He”, “”, $var1); // llo!

– ?>

2. User-defined functions

– <?php

– function add($a, $b){

– return $a+$b;

– }

– echo add(100, 200); // 300

– ?>

July 22, 2012

FOR ALL KINDS OF PURPOSES Intel Corporation

Topic #3:Anatomy Of A WordPress Theme

15

FOR ALL KINDS OF PURPOSES16Intel Corporation

Mobile Augmented Reality

Anatomy of a WordPress theme

• Contents1. Main Parts2. Sections for “The Loop”3. The Loop4. Additional Files5. The Extras

• Reference– http://yoast.com/wordpress-theme-anatomy/

July 22, 2012

FOR ALL KINDS OF PURPOSES17Intel Corporation

Mobile Augmented Reality

Anatomy of a WordPress theme: Main Parts

July 22, 2012

FOR ALL KINDS OF PURPOSES18Intel Corporation

Mobile Augmented Reality

Anatomy of a WordPress theme: Sections for “The Loop”

July 22, 2012

FOR ALL KINDS OF PURPOSES19Intel Corporation

Mobile Augmented Reality

Anatomy of a WordPress theme: The Loop

July 22, 2012

FOR ALL KINDS OF PURPOSES20Intel Corporation

Mobile Augmented Reality

Anatomy of a WordPress theme: Additional Files

July 22, 2012

FOR ALL KINDS OF PURPOSES21Intel Corporation

Mobile Augmented Reality

Anatomy of a WordPress theme: The Extras

July 22, 2012

Thank you for your attention!any Question?