Classes

Class on Tuesday 3.12.13

Today we are going to spend some time talking about and then working on Assignment #4. I want to give you some time today to work on your own to help you gauge what you understand and don’t understand. On Thursday we will look at where you are having problems.

 

Class on Thursday 3.7.13

Today we are going to continue where we left off on Tuesday with creating a theme from scratch. If you weren’t here on Tuesday or don’t have your files then head over to the Class Files page and download the files.

When you do download those files, or in your own files, there is an error I introduced at the end of last class you need to correct. Open header.php and comment out the <div class=”mainContent”>. we moved this into content.php.

I made a new resource: Theme Template Tag Cheat Sheet which is not complete but will hopefully help with finding and remembering all of the tags you need.

Class on Tuesday 3.5.13

We got through starting a theme and converted the basic header and footer. The files from class are in the Class Files section for 3.5.13

Today we will start with creating themes. It is chapter 4 in the book

We will use these files for today

StartingHTMLCSS.zip

and start to convert them into a theme.

Diagram to help explain below.

Class on Tuesday 2.26.13

Update

Today we changed things a bit and added in a lesson on installing and using Sublime and the Emmet and WordPress packages for Sublimt Text 2. There is a separate post on Sublime here:

We then went through the first 3 STEPS of Assignment 3. These are essentially the steps that get the blog and the theme ready to add the code to put loops on the page.

As part of our working through thos steps we also looked at the query_posts() function and downloaded my example page template that uses query_posts:page-test-query-posts.php.zip. When you are using this yourself there are a couple of things to keep in mind:

  • You need to download and unzip the file before adding it to your Theme.
  • The page template was created with the idea that it would be added to the Twenty Ten theme.
  • To see the page that uses query_posts in action you have to assign the “Test query posts” template to a page and then view that page.
  • You need to go in and change the code in page-test-query-posts.php so that the part that reads
  • $args = array(‘cat’ => 13 ); is changed to
  • $args = array(‘cat’ => x ); where x is the id of a category on your blog

You can find the id of a category on your blog by going to the Posts>Categories page in the Dashboard and then clicking on a category and looking for tag_ID=13 in the URL. The number is the category id. (also most browsers show the URL of a link somewhere near the bottom of the browser window if you hover over the link, so you can see the number there).

Before we did the query posts thing we had already added the sample posts as outlined in STEP 2 of Assignment 3.

My files from today can be found in the Class Files page.

Outline

Today we are going to focus on the loop again. We will start with going over the setup stuff for assignment #3. Then we will look at two different ways to make a custom loop. But first we will talk about the default query

Default Query

The WordPress Loop is based on a query made to the database that stores all of the information in WordPress. If no query has been made then there is no information to loop through. Changing the query changes what kind of information is shown in the loop.

By default WordPress makes a query based on what you’re showing. If you’re showing the front page and have set it up to show posts (NOT static) then WordPress will do a query for the most recent posts and the Loop will use that. If you’re on a page WP will make a default query to get the information for that particular page only and the Loop will use that info.

Sometimes however you want different or more information that might be contained in the default query. That is what the next two queries are for.

query_posts()

This function replaces the default query when it’s run. It goes out and gets information based on arguments that you provide and then you can use the loop like normal to display the information.

page-test-query-posts.php.zip

Download this file (and unzip it), and add it to the theme you’re using. We will write some code that will show the page content and then show all of the posts in a particular category after that.

You can use a similar idea to show posts or excerpts of posts based on other arguments (date, author etc).

WP_Query()

One of the problems with query_posts() is that it resets the default query. That makes it difficult to have more than one loop on a page and can mess with existing loops.

WP_Query() to the rescue. It is very similar to query_posts() except that you store the information in a variable. Then you need to use this variable when you’re making the loop.

Here is an example of how you create the WP_Query
$args = array(‘cat’ => 13 );
$ featured_query = new WP_Query( $ args );

But then you use it in a different way.

So for example This is a standard Loop:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> 

And this is one with the $featured_query from above

<?php if ( $ featured_query-have_posts() ) : while ( $ featured_query-have_posts() ) : $ featured_query-the_post(); ?> 

So you add the $featured_query in front of everything.

Then after that you use the loop like normal. But you can use this multiple times throughout the page.

Class on 2.19.13

Outline of the day

Template Tags

  1. Background on WordPress Template Hierarchy: http://codex.wordpress.org/Template_Hierarchy
  2. Download the TwentyTwelve-2.19.13 theme: twentytwelve-2.19.13.zip
  3. Page Templates
    1. Open the test-page.php page template file.
    2. Create a page that uses that template
    3. Have it use sidebar-new.php instead of sidebar.php
  4. Duplicate sidebar.php and rename it sidebar-new.php
  5. Add Link to RSS feed in the sidebar-new.php using the bloginfo() Template Tag: http://codex.wordpress.org/Function_Reference/bloginfo
  6. Add in a tag cloud using the wp_tag_cloud() template tag http://codex.wordpress.org/Function_Reference/wp_tag_cloud
    1. We will also talk about template tag arguments and use them for the wp_tag_cloud()
  7. Conditional Tags
    1. What are they
    2. Examples of Conditional Tags

The Loop

This starts in chapter 3 in the book. We are going to start this out. We might not get to it until Thursday.

  1. What is the loop
  2. Download modified Twenty Ten theme and follow along in the book.
    1. twentyten-chapter3-start.zip
  3. Below are some images that help clarify what the book asks you to do
    1. This file contains a basic loop: BasicLoop.php

The Basic Loop

Asking for a particular loop file using get_template_part()

Adding in the Excerpt

Removing Filters in functions.php

Adding CSS to style.css’

Reminder no class on Tuesday 2.12

Hi Class, just a reminder that there is no class today, Tuesday 2/12/13.

Also, Assignment #2 is now up. It is due on Friday, but you should be able to finish it before class on Thursday. Since it isn’t due until Friday you can ask questions on Thursday’s class (so start before then).

I will see you in class on Thursday.

Class on 2.7.13

Today we are going to make sure everyone has WordPress installed somewhere (see my updated post on installing Server2Go on a USB) and then jump into what is in the book  ”Chapter 2: The WordPress Syntax”

We will see the different pieces that make up a WordPress theme and experiment with changing things to help you see how it fits together.