What is the Loop?
- It's the core of Wordpress
- It's a heap of PHP code over different files that works together.
For most people, the Loop is somewhat of black box, most people never think about it or how it works.
So where is the Loop?
- Wordpress uses one central control point
- It's your theme's control.
- All requests go via this file -index.php
- If you remove it you get the default theme.
- Remove that and you get ... well, nothing.
Please see the slides for more detailed information on the Loop and a breakdown of the Loop Code.
Things to do with the WordPress Loop
We can customise the Loop
- Change archive and search paes to display excerpt
- Customise the CSS for different times, dates, categories, *authors or days of the week.
- Change our home page to a static one
- place items between blog posts
- add a lemon
- Before you start adding or removing things, BACK UP!!
- check for plugins or widgets first
More Notes
What we will talk about:
- Go through and discuss how the Wordpress Loop works.
Audience
- Assume you know what wordpress is
- Know how to use plugins, widgets etc.
- Working on your own blog, not wordpress.com etc. You need to be able to edit the code
- Assume you know PHP (dont have to be coder)
- Not happy coding!
- You have never pulled templates apart
What is the Loop
- core of wordpress, without it doesn't operate
- PHP over different files that work together
- Lets you display your posts, comments and the rest of your blog. Renders your blog onto the screen.
- To most people, the Loop is a Black Box. Don't have to worry about how things work at the backend.
Where is the Loop?
- central control point is in index.php of the THEME
- All requests go through this file.
- Remove it, and it goes to the default theme
- Remove the default theme... and you get nothing. The whole thing stops. No error message.
How does it work
- PRetty basic:
- Showing the code ie. get_header > have_posts > while loop to get the post / content > get_sidebar and > get_footer
- have_posts IS THE LOOP
- In detail:
- Section 1:: Have_posts, while have_posts: this checks the information, to see if you have posts or not
- Then, move into the loop (Gary shows picture of recursive cats looking at cats on computers... )
- Section 2:: Gets the posts and more information
- Section 3:: the_content * displays the posts and information.
Looking even closer:
- Get information with the post, along with secondary information
- Post Title
- Publication Date
- Author
- Categories
Then wordpress displays all your posts...
After, goes back to the top of the loop. It goes "around, and around, and around" depending how many posts that you have got whether that be 4500 posts or 2 posts.
Shows an example of the default template code. Stepping through:
{get header}
[some html]
{have posts} [html code] [secondary data calls]
{get sidebar}
{get footer}
In detail:
If you want to display something After Every Single Post (a LOLCat maybe??) you need to do it between {the_content} and {endwhile}. Examples: an Edit Post link for when you're logged in, Display of category, Permalink, Date and Time, Author, Comment Count * any of these can be moved from the title to a bar at the bottom of the post. Can display these multiple times in the post.
After the loop, after {endwhile} you can put in Previous/Next Entry links.
If navigation is wrong, or its playing up, usually in this area.
The Loop is Breeding
- All through wordpress
- In the archive template
- In the search template
- Even used in the generation of comments
What can you do with the Loop? Customise it:
- Change Archive and Search pages to display exceprt
- Customise CSS for different times, dates, categories, or authors. Eg. every wednesday you have a green backgrounds with lemons!
- Change home page to a static one
- Place items between blog posts
Basically: just put whatever you want before that {endwhile}
But: check for plugins or widgets first. For all the items above, there's a plugin available to do that! Maybe even to add Lemons.
http://www.radharc.com.au
http://www.manwithnoblog.com
See also Liveblog post by Kate Quinn