Your SlideShare is downloading. ×
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Getting Into The Loop
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Getting Into The Loop

38,176

Published on

The magic behind WordPress is how it processes queries and gives you the results via “The Loop.” The Loop can be hijacked for a variety of custom uses and these techniques can quickly expand the …

The magic behind WordPress is how it processes queries and gives you the results via “The Loop.” The Loop can be hijacked for a variety of custom uses and these techniques can quickly expand the capacity of WordPress to present information in different ways. We’ll cover this, as well as PHP tips which help introspect WordPress during lower-level development.

Published in: Technology, Business
9 Comments
41 Likes
Statistics
Notes
  • Please upload a PDF
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • very good, thanks
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Thanks for this eye opener you really know what you are talking about. I am an experienced web developer - but I am very new to Wordpress customization.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • @nomadone '.key' is the native format for Apples Keyonte. It's neither strange nor unaccessible, but i does require you to own the program in question. Unfortunatly there´s no free viewer for Windows, so i suggest to the presentation owner to offer the presentation in pdf instead.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Nice presso. I tried downloading it and just get a strange unaccessible 'key' file. I tried changing the file format into pdf and ppt and keep getting error messages.

    Any ideas on how to convert this file into a usable format?

    Thanks for giving us free access to this file!
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
38,176
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
548
Comments
9
Likes
41
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • We have a good deal of content to cover.
    I may defer questions to the end. I can stick around later to answer questions too.
  • We have a good deal of content to cover.
    I may defer questions to the end. I can stick around later to answer questions too.
  • My WP claim to fame
  • My WP claim to fame
  • My WP claim to fame
  • My WP claim to fame
  • My WP claim to fame
  • Knowing just this will help you modify themes intelligently.
  • the source - get it local, grep on it.
  • the source - get it local, grep on it.
  • the source - get it local, grep on it.
  • the source - get it local, grep on it.
  • the source - get it local, grep on it.
  • Transcript

    • 1. Getting Into The Loop mitcho (Michael Erlewine) http://mitcho.com January 23, 2010 WordCamp Boston
    • 2. Today • Introduction • Loop basics • Custom queries • Method 1: Roll your own query • Method 2: Filter every query • Next steps
    • 3. Today NOTE: • Will link to slides and code later on http://mitcho.com/blog/ • Please rate later on SpeakerRate (find link on the blog)
    • 4. Today • Introduction • Loop basics • Custom queries • Method 1: Roll your own query • Method 2: Filter every query • Next steps
    • 5. Introduction
    • 6. Introduction • Hi, I’m mitcho.
    • 7. Introduction • Hi, I’m mitcho. • Linguist, coder, teacher.
    • 8. Introduction • Hi, I’m mitcho. • Linguist, coder, teacher. • At MIT. Previously at Mozilla. Now working with Automattic.
    • 9. Introduction • Hi, I’m mitcho. • Linguist, coder, teacher. • At MIT. Previously at Mozilla. Now working with Automattic. • Programming PHP/MySQL since 2002?
    • 10. Introduction • Hi, I’m mitcho. • Linguist, coder, teacher. • At MIT. Previously at Mozilla. Now working with Automattic. • Programming PHP/MySQL since 2002? • Blogging (off and on) since 2007.
    • 11. Introduction • Hi, I’m mitcho. • Linguist, coder, teacher. • At MIT. Previously at Mozilla. Now working with Automattic. • Programming PHP/MySQL since 2002? • Blogging (off and on) since 2007. • http://mitcho.com; @mitchoyoshitaka
    • 12. Introduction
    • 13. Introduction • Yet Another Related Posts Plugin
    • 14. Introduction • Yet Another Related Posts Plugin • ...aka YARPP
    • 15. Introduction • Yet Another Related Posts Plugin • ...aka YARPP • As seen on Laughing Squid, ma.tt...
    • 16. Introduction • Yet Another Related Posts Plugin • ...aka YARPP • As seen on Laughing Squid, ma.tt... • Over 350k downloads
    • 17. Introduction • Yet Another Related Posts Plugin • ...aka YARPP • As seen on Laughing Squid, ma.tt... • Over 350k downloads • http://mitcho.com/code/yarpp or search for “YARPP”; @yarpp
    • 18. Today • Introduction • Loop basics • Custom queries • Method 1: Roll your own query • Method 2: Filter every query • Next steps
    • 19. The Loop
    • 20. The Loop • “The Loop” is the mechanism by which posts are called from the database and then displayed.
    • 21. The Loop • “The Loop” is the mechanism by which posts are called from the database and then displayed. • On many pages—like the index or archives—it “loops” through each post.
    • 22. The simplest Loop get_header(); if (have_posts()) : while (have_posts()) : the_post(); the_content(); endwhile; endif; get_sidebar(); get_footer();
    • 23. The simplest Loop get_header(); if (have_posts()) : { while (have_posts()) : the_post(); “The Loop” the_content(); endwhile; endif; get_sidebar(); get_footer();
    • 24. The simplest Loop get_header(); if (have_posts()) : { while (have_posts()) : “The Loop” the_post(); Sets up the post the_content(); endwhile; endif; get_sidebar(); get_footer();
    • 25. The simplest Loop get_header(); if (have_posts()) : { while (have_posts()) : “The Loop” the_post(); Sets up the post the_content(); endwhile; endif; get_sidebar(); get_footer(); Every theme’s PHP files are built on this basic structure.
    • 26. The Loop if there are posts while there are posts get the post do stuff with it end while end if
    • 27. The Loop if there are posts { while there are posts get the post “The Loop” do stuff with it end while end if
    • 28. The Loop
    • 29. The Loop • The Loop is where you can use Template Tags.
    • 30. The Loop • The Loop is where you can use Template Tags. • codex.wordpress.org/ Template_Tags
    • 31. The Loop • The Loop is where you can use Template Tags. • codex.wordpress.org/ Template_Tags • It’s the the_post() call that makes that possible.
    • 32. The Loop if there are posts while there are posts get the post do stuff with it end while end if CC BY flickr.com/photos/myklroventine/ 1430113497/
    • 33. The Loop But mommy, where do posts come from? if there are posts while there are posts get the post do stuff with it end while end if CC BY flickr.com/photos/myklroventine/ 1430113497/
    • 34. The Loop But mommy, where do posts come from? if there are posts while there are posts get the post do stuff with it end while end if CC BY flickr.com/photos/myklroventine/ 1430113497/
    • 35. Every Loop has a query
    • 36. Every Loop has a query • Regularly, WordPress chooses the right template file and query based on your URL.
    • 37. Every Loop has a query • Regularly, WordPress chooses the right template file and query based on your URL. • codex.wordpress.org/ Template_Hierarchy
    • 38. Every Loop has a query • Regularly, WordPress chooses the right template file and query based on your URL. • codex.wordpress.org/ Template_Hierarchy • /archives/123 → single post
    • 39. Every Loop has a query • Regularly, WordPress chooses the right template file and query based on your URL. • codex.wordpress.org/ Template_Hierarchy • /archives/123 → single post • /archives→ archives
    • 40. Every Loop has a query • Regularly, WordPress chooses the right template file and query based on your URL. • codex.wordpress.org/ Template_Hierarchy • /archives/123 → single post • /archives→ archives • /tags/chicken→ all chicken articles
    • 41. Today • Introduction • Loop basics • Custom queries • Method 1: Roll your own query • Method 2: Filter every query • Next steps
    • 42. Customizing The Loop
    • 43. Customizing The Loop • Themes control how information is presented...
    • 44. Customizing The Loop • Themes control how information is presented... • The query controls what information is presented.
    • 45. Custom queries
    • 46. Custom queries Possible applications:
    • 47. Custom queries Possible applications: • Create custom feeds/displays
    • 48. Custom queries Possible applications: • Create custom feeds/displays • ephramzerb.com/projects/feed- wrangler/
    • 49. Custom queries Possible applications: • Create custom feeds/displays • ephramzerb.com/projects/feed- wrangler/ • Pull information on other posts from within the theme’s Loop
    • 50. Custom queries Possible applications: • Create custom feeds/displays • ephramzerb.com/projects/feed- wrangler/ • Pull information on other posts from within the theme’s Loop • Customize what information is displayed globally
    • 51. Custom queries Possible applications: • Create custom feeds/displays • ephramzerb.com/projects/feed- wrangler/ • Pull information on other posts Today’s from within the theme’s Loop examples • Customize what information is displayed globally
    • 52. Today • Introduction • Loop basics • Custom queries • Method 1: Roll your own query • Method 2: Filter every query • Next steps
    • 53. Roll your own query
    • 54. Roll your own query EX:
    • 55. Roll your own query EX: • Pull information on other posts from within the theme’s Loop
    • 56. Roll your own query EX: • Pull information on other posts from within the theme’s Loop • Display other posts with a specific criteria, like a tag.
    • 57. Roll your own query EX: • Pull information on other posts from within the theme’s Loop • Display other posts with a specific criteria, like a tag. • Wrap it up in a shortcode [others]
    • 58. Roll your own query
    • 59. Roll your own query The idea:
    • 60. Roll your own query The idea: • Create a new WP_Query object.
    • 61. Roll your own query The idea: • Create a new WP_Query object. • Given a $tag...
    • 62. Roll your own query The idea: • Create a new WP_Query object. • Given a $tag... • new WP_Query(array('tag'=> $tag))
    • 63. Roll your own query The idea: • Create a new WP_Query object. • Given a $tag... • new WP_Query(array('tag'=> $tag)) • Call it $my_query
    • 64. Roll your own query The idea: • Create a new WP_Query object. • Given a $tag... • new WP_Query(array('tag'=> $tag)) • Call it $my_query • Create a Loop for $my_query
    • 65. Roll your own query The idea: • Create a new WP_Query object. • Given a $tag... • new WP_Query(array('tag'=> $tag)) • Call it $my_query • Create a Loop for $my_query • Do stuff in it
    • 66. Make your own Loop Make sure the Loop controllers are using $my_query, not the default ($wp_query) if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); the_content(); endwhile; endif;
    • 67. The result:
    • 68. DEMO:
    • 69. More about WP_Query
    • 70. More about WP_Query Learn more from the Codex:
    • 71. More about WP_Query Learn more from the Codex: • More information on the parameters:
    • 72. More about WP_Query Learn more from the Codex: • More information on the parameters: • codex.wordpress.org/ Template_Tags/query_posts
    • 73. More about WP_Query Learn more from the Codex: • More information on the parameters: • codex.wordpress.org/ Template_Tags/query_posts • Tips and examples:
    • 74. More about WP_Query Learn more from the Codex: • More information on the parameters: • codex.wordpress.org/ Template_Tags/query_posts • Tips and examples: • codex.wordpress.org/The_Loop
    • 75. Today • Introduction • Loop basics • Custom queries • Method 1: Roll your own query • Method 2: Filter every query • Next steps
    • 76. Filter every query
    • 77. Filter every query EX:
    • 78. Filter every query EX: • Customize what information is displayed globally.
    • 79. Filter every query EX: • Customize what information is displayed globally. • Hide all my tweets.
    • 80. Filter every query
    • 81. Filter every query The idea:
    • 82. Filter every query The idea: • Use the request filter to specify that we don’t want results from the “tweet” category (#10)
    • 83. The result:
    • 84. DEMO
    • 85. Aside: the tools Turn up the fire! • Firefox getfirefox.com • Firebug getfirebug.com • FirePHP firephp.org
    • 86. Aside: the tools Turn up the fire! • Firefox getfirefox.com • Firebug getfirebug.com • FirePHP firephp.org The “Pyrotrinity”
    • 87. FirePHP Takes a moment to set up:
    • 88. FirePHP Takes a moment to set up: Use it like this:
    • 89. Today • Introduction • Loop basics • Custom queries • Method 1: Roll your own query • Method 2: Filter every query • Next steps
    • 90. Next steps
    • 91. Next steps Hit the docs:
    • 92. Next steps Hit the docs: • PHP manual: php.net
    • 93. Next steps Hit the docs: • PHP manual: php.net • Codex: codex.wordpress.org
    • 94. Next steps Hit the docs: • PHP manual: php.net • Codex: codex.wordpress.org • The source: core.trac.wordpress.org
    • 95. Next steps Hit the docs: • PHP manual: php.net • Codex: codex.wordpress.org • The source: core.trac.wordpress.org • grep it!
    • 96. Next steps
    • 97. Next steps Learn SQL
    • 98. Next steps Learn SQL • The language that WordPress’s raw database calls are in.
    • 99. Next steps Learn SQL • The language that WordPress’s raw database calls are in. • It’s really not that scary.
    • 100. Next steps Learn SQL • The language that WordPress’s raw database calls are in. • It’s really not that scary. • Lets you write filters directly on different parts of the query.
    • 101. Next steps Learn SQL • The language that WordPress’s raw database calls are in. • It’s really not that scary. • Lets you write filters directly on different parts of the query. • EX: mitcho.com/blog/how-to/external- orders-in-wordpress-queries/
    • 102. Thank you! Questions? Slides will be up on mitcho.com/blog/. See you at the Genius Bar! mitcho (Michael Erlewine) mitcho.com; @mitchoyoshitaka

    ×