Ladies Learning
WordPress
Wes Bos
@wesbos
WesBos.com
Wes Bos
@wesbos
WesBos.com
An Open Source Content Management System used to power thousands of websites
Initially was used to power blogs
Powerful enough to run large websites and applications
Used by Mashable,CNN and many more...
WordPress.com is Hosted for you - No servers or code required!
.com Doesnt allow for a lot of customization
We will be using .org
Self-Hosted allows for 100% customization. Yay!
localhost - / Local Server (MAMP or WAMP) - A small service that runs on your laptop which mimics the functionality of a large, paid server (like GoDaddy). We are able to work on our website without uploading it anywhere.
PHP tags - PHP is the programming language WordPress is written in. when we need to use PHP, we put it inside <?php and ?> tags so our server will know to process it as PHP.
stylesheet - The style.css file within our theme. From this file we control the colours, fonts, sizes and all style elements for our website.
Dashboard - The WordPress backend you see when you first log into your website
Codex - The WordPress documentation. Very helpful when you require a reference or assistance with a certain part of WordPress. http://codex.wordpress.org/
Permalinks - Human readable URL. When turned on, WordPress changes the url structure from something like MySite.com/?p=54 to MySite.com/contact-me
Theme - The collection of files that we use to lay out and style our WordPress website. WordPress allows you to easily change and modify themes without losing any of your posts or pages.
Template - A specific file within our theme that lays out either an entire page or part of a page. For example, page.php is the template within our theme that lays out the structure for all of our pages
Post - A piece of content that is stored within the database. When we use the word post, we are referring to a blog post.
Plugin - An installable package that adds functionality to your wordpress website.
Query - A ping to the database that asks for certain posts based on several supplied parameters.
The database holds our data and the code defines how and when the data is printed to the page
The two work together to output HTML
/wp-admin and /wp-includes holds the engine of WordPress - we don't touch it.
/wp-content holds our specific content like themes, plugins and image uploads.
Step 1: Unzip the wordpress package you downloaded, you'll have a folder called wordpress
Step 2: Move that Folder over to your localhost.
If you need help findind the folder: Windows: Click WAMP icon in tray → www directory Mac: click MAMP icon → Preferences → Apache Tab
Step 3: Open up PHPmyadmin and create a DB called llc
Windows: Go to http://localhost Mac: Go to http://localhost:8888/MAMP/ Both: click PHPMyAdmin
Step 4: Rename wp-config-sample.php to wp-config.php and open it
Step 5: Set the below.
Windows Users: Leave password blank.
Step 6: Surf to http://localhost/wordpress or http://localhost:8888/wordpress in Chrome and install!
Create 7 posts, fill them with some dummy content Make sure to add a few tags/categories to each.
Create 3 pages called Blog, Contact and Home
The Boring parts are almost done, I promise!
Set Blog page and home page accordingly
Settings->Reading

Remember Permalinks? Lets turn on pretty permalinks
Settings->permalinks

I'm so proud, heres a UTF-8 star
★
Themes control how your site looks
Your Data (Posts, Page, Comments...) is stored in the database so you wont lose your data if you switch!
There is no limit to what a WordPress theme can look like
There are thousands of themes available for free or for pay
Many great WP Developers got their start tweaking exisitng themes
So... Thats what we're going to do today!
Wordpress.org/extend/themes - All Free
Themify.me Paid & Free
WooThemes.com - Paid and Free
ThemeForest.net - Paid / Inexpensive
Dashboard → Appearance → Themes → Install Themes Tab
We can Search and install right from this interface!
The default theme is a little confusing, lets install a simpler one!
All themes live in /wp-content/themes
Unzip llctheme.zip and drag+drop into wordpress/wp-content/themes

Dashboard → Appearance → Themes
We Now see our Ladies Learning Code Theme, go ahead and activate it.
A WordPress Theme is made up of a number of template files that are used to display different pages on your site
single.php is used to show a single blog post while index.php is used to display the main blog page listing your most recent posts. More on this later.
Most template pages can be stripped down the following:
<?php get_header(); ?>
{ The Page's Content and the Loop live Here}
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Let's get comfortable with the basic building blocks of our theme. We're going to edit header.php, sidebar.php and footer.php
Open footer.php add your name to the copyright. Save it and refresh your website.
You now have your name at the bottom of your website. Easy, eh?
Let's step it up a notch!
Placing an image in the header.
Step 1: Open header.php and find the line that looks like this:
<h1><a href="<?php echo home_url( '/' ); ?>">
<?php bloginfo( 'name' ); ?></a></h1>
Delete it!
Now we're going to do two things: 1. Create a link, 2. Put an image inside that link.
<a href="<?php echo home_url( '/' ); ?>">IMAGE HERE</a>outputs:
<a href="http://localhost/wordpress">IMAGE HERE</a>Add the Image
We need the path to the image and the file name
<img src="<?php bloginfo("template_directory"); ?>/i/header.png" />
outputs:
<img src="http://localhost/wordpress/wp-content/themes/ladies-learning-code/i/header.png" alt="">
<a href="<?php echo home_url( '/' ); ?>">
<img src="<?php bloginfo("template_directory"); ?>/i/header.png" />
</a>
You should now have a banner image in your header
Open sidebar.php and look for these comments:
We're going to use the same image code as we used in the header. Our file is called portrait.png
<img src='<?php bloginfo('template_directory'); ?>/i/portrait.png' />
Underneath, write a little something about yourself. Wrap it in <p> and </p> tags.
<p>Welcome to my blog, I'm really into learning how to code!</p>
You should now have an image in your sidebar
Different Pages can be displayed with different layouts.
Example: 2010 Archives can have a different layout than a category view.
Let's take a look at the important template files ones in our theme...
archive.php Shows Archives of old posts
author.php - Displaying all posts by a certain author
category.php - Displaying all posts within a certain Category
footer.php - The footer that is appended at the bottom of every page
functions.php -Commonly used for enabling theme features such a custom navigations and post thumbnail sizes
header.php- The footer that is appended at the bottom of every page
index.php- The front page of your blog, displays the latest n posts
loop.php - A reuseable file to display posts (much more later!)
page.php- Default template for displaying pages
search.php- Template for displaying search results
sidebar.php- Sidebar that is appended to every page
single.php- Default template used for displaying a single post
tag.php - Displaying all posts within a certain tag
Now that we have a good feel for our theme layout, let's customize it a little more
1. Change the background colour and add an image
2. Change the link underline colour
3. Take the underline off the links only in the sidebar
4. Add a hover colour to our navigation
Open your style.css file
Locate the line that sets the body background colour
Change it to whatever colour you want!
#BADA55 #B1009A pink
papayaWhip goldenrod seaGreen
whiteSmoke
tomato
thistle
skyBlue
yellowGreen
Take it one step further and add an image into the background
background: #fff url(i/background.png);
All of our links have a yellow underline. We use the a selector in our style.css file to specify the bottom border.
Find the following line and change #ECD018 to a new colour
border-bottom:1px solid #ECD018;
#BADA55 #B1009A pink
papayaWhip goldenrod seaGreen
whiteSmoke
tomato
thistle
skyBlue
yellowGreen
lemonChiffon
We don't need underlines on the sidebar links.
With CSS we can target only the links in the sidebar and specify no underline
Scroll down in your style.css and find the Sidebar Section
Apply a new style to .sidebar a like so:
.sidebar a {
border-bottom:0;
}
If you like, go crazy adding more styles to your sidebar links.
For this, we use the CSS pseudo selector, :hover
Our regular selector looks like this
.menu ul li a {...}
So our hover selector looks like this
.menu ul li a:hover {...}
Lets add a #BADA55 background
.menu ul li a:hover { background: #BADA55;}
The loop is the lifeblood of a WordPress Theme, is it use to iterate over and display each of the posts that are available on a given page.
“For as long as there are posts to show, show them”
Our home page loop shows 5 posts, but a single post page only shows 1.
Every page has at least a basic loop to output that page's content.

This is the logic behind the loop in plain english
if we have posts
while we have posts
1. The Code in here is run once for every piece of content
retrieved from the database
2. We might want to output the title, the date and the content
end while
end if
Lets step through how WordPress works if someone visits your blog home page and when someone visit your blog page.
1. The blog page is requested by the user. Wordpress asks the database for all content for that page.
2. The database returns 5 of the latest blog posts
3. Wordpress first grab the header.php file and starts the page output
4. Wordpress then hits the loop. Since we have 5 posts from the database, we output the code within the loop 5 times
5. Wordpress is done the loop, it moves on and outputs the sidebar and the footer
A stripped down look outputting only the title and the content.
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php endwhile; ?>
Our wordpress theme comes with the loop.php which handles most of this for you.
You just need to be aware of how the loop works and what it looks like so you can edit it!
Wondering how to actually get your content onto the page while you're inside the loop?
Template tags are short little PHP functions that will output content from your site.
No knowledge of PHP is required.
Most template tags only work within the loop
Others are global and can be used anywhere on the site
Remember we used <?php echo home_url( '/' ); ?> in our header?
There are hundreds of template tags
http://codex.wordpress.org/Template_Tags
Lets take a look at some of the commonly used ones.
<?php the_title(); ?>
<?php the_content(); ?>
<?php the_excerpt(); ?>
<?php the_permalink(); ?>
<?php the_time(); ?>
<?php the_tags(); ?>
<?php the_category(); ?>
<?php comments_template(); ?>
<?php the_author(); ?>
<?php the_post_thumbnail(); ?>
1. Open single.php in your editor
Type Hello, I'm editing single.php! on the first line available in the safe zone.
Save the file and go to a single post on your website
Do you see where it says Hello, I'm editing single.php!
We dont see this on any other page because single.php only controls single blog posts.


Want to associate an image with each of your posts? Go into the wordpress admin an edit one of your posts.
At the bottom right, click set featured image.
Select and upload a file
When the upload is finished, scroll down and select "use as featued image"
Click update 
and then view the post. 
The image doesn't appear! Why not? We need to use the template tag to add it to our theme!
Remember <?php the_post_thumbnail(); ?> Place it just above our <?php the_content(); ?> template tag

Almost Perfect, lets pass our tag some options to left align.
<?php the_post_thumbnail('thumbnail', array('class' => 'alignleft')); ?>
We're going to use the Facebook and Twitter API to embed the like/tweet buttons into our page
Since each page is dynamic, we need to supply the like/tweet button with a link to whatever post we are on
We're going to use the template tag
<?php the_permalink(); ?> to generate this.




Copy and paste that code into the Social Media Zone in single.php
Save your page and refresh a post page. See your new tweet button!
Now lets do Facebook...
1. In URL to Like type "FILL_ME_IN"
2. Uncheck "Send Button"
3. Go ahead and choose your own settings!
4. Click "Get Code"
5. Click IFRAME tab and copy the code 
Paste your code underneath your twitter code.
The last step is to replace FILL_ME_IN with our template tag <?php the_permalink(); ?>
Save and refresh your page. Now we have both twitter and facebook buttons!
Sometimes we dont want the same old structure for every single page
What if we want one page to have a totally different structure? No sidebar? Three Columns? Full page map?!
The sky is the limit!
For this, we use something called custom page templates
We can create many tempaltes that are similar to page.php and assign them to various pages
We're going to create two custom page templates
The first one will be a simple page without a sidebar for our contact page.
The second will be our custom landing page for our home page.
Lets get started!
Step 1: Duplicate our page.php file and rename it page-contact.php
Step 2: at the top of page-contact.php let name our template with:
<?php /* Template Name: Contact Page */ ?>
Step 3: We don't want a sidebar for this page, so go ahead and delete <?php get_sidebar(); ?>. Save.
Step 4: Go to the WordPress dashboard, and edit your contact page.
You'll now see under "Page Attributes" we have a template dropdown.

Select Contact Page and click update then view. 
Let's create a new page called page-home.php
This time, fill it with the following Markup:
<?php /* Template Name: Home Page */ ?>
<?php get_header(); ?>
<div class="home">
Coming Soon...
</div>
<?php get_footer(); ?>
Edit your home page and assign the "Home Page Template"
We will come back to this in our final exercise!
Widgets are modular items that can be added to your sidebar
How do we add one?
Let's add our latest tweets to our sidebar!
http://twitter.com/about/resources/widgets/widget_profile

Click "Finish and grab Code"
Step 1: Dashboard → Appearance → Widgets
Step 2: From the Available Widgets box, Drag and drop the text widget into your "Primary Widget Area"
Step 3: Fill in a Title of your choice.
Step 4: Paste the code that twitter provided you into the big white box. Click Save.


WordPress can only include so much functionality in the base package
When you need more functionality, plugins come to the rescue!
There is a huge community of developers that create plugins that you can install for free.
Can be as small as adding a popup photo gallery to as large as running a social network!
All Plugins live in /wp-content/plugins but we can also interface with them via the dashboard, just like themes!

You can Delete the plugins you don't want

And Activate the ones you need

Akismit is 100% required to block spammers, you must sign up for a Free account
wp-pagenavi
Advanced custom fields
Custom Post Type UI
Share This
Subscribe To Comments
Contact Form 7
Quick Cache
Anyone have a favourite?
This is your time to shine and put everything you have learned today to work.
Step 1: From the dashbaord, edit your "Home" page. Write a few lines about yourself and upload a photo.
Step 2: Remember our page-home.php? Open it up again and delete "Coming Soon..."
Step 3: We're now going to write our own loop so we can get the page's content.
<?php if(have_posts()) while(have_posts()) : the_post(); ?>
<?php endwhile; ?>
Step 4: Inside the loop, we will put a div with the class of homeBlurb and use our template tag <?php the_content(); ?> to fetch the content from our home page.
Our loop now looks like this:
<?php if(have_posts()) while(have_posts()) : the_post(); ?>
<div class="homeBlurb"><?php the_content(); ?></div>
<?php endwhile; ?>
Now that we have our Home content pulling in, lets work on our three columns.
Step 5: Right underneath <?php endwhile; ?>, create an empty div with the class of homeColumn.
<div class="homeColumn"></div>
Step 6: Inside that div, insert an <h3>Tag Cloud</h3> along with our template tag <?php wp_tag_cloud(); ?>
<div class="homeColumn"> <h3>Tag Cloud</h3> <?php wp_tag_cloud(); ?> </div>
Step 7: Create another column with the class of homeColumn but this time inside we're going to put the template tags for pulling in the latest posts
Here we use the <?php wp_get_archives(); ?> template tag.
<div class="homeColumn">
<h3>Latest Posts</h3>
<ul> <?php wp_get_archives('type=postbypost&limit=10'); ?> </ul>
</div>
We wrap our template tag in <ul> and </ul> because it is a unordered list of posts.
Step 8: Create our third and final column. This time we use template tags to pull in a list of categories.
Here we use the <?php wp_list_categories(); ?> template tag.
<div class="homeColumn">
<h3>Categories</h3>
<ul> <?php wp_list_categories('title_li='); ?> </ul>
</div>
Step 9: You're done! I've provided you with some minimal style in your style.css file. Find the section marked "CUSTOM HOME PAGE STYLE" and go crazy making it your own!
Custom Post types
Advanced backend interfaces
Social Network community with buddypress
Plugin Development is an whole ‘nother world
WordCamps and Meetups - The WordPress community is amazing
http://wordpress.stackexchange.com/
#WordPress on freenode
WordPress forums
The codex is the most valuable thing in the world.