SlideShare uma empresa Scribd logo
1 de 102
Getting Into The Loop
mitcho (Michael 芳貴 Erlewine)
http://mitcho.com

January 23, 2010
WordCamp Boston
Today

• Introduction
• Loop basics
• Custom queries
 • Method 1: Roll your own query
 • Method 2: Filter every query
• Next steps
Today

NOTE:
 • Will link to slides and code later
   on http://mitcho.com/blog/
 • Please rate later on SpeakerRate
   (find link on the blog)
Today

• Introduction
• Loop basics
• Custom queries
 • Method 1: Roll your own query
 • Method 2: Filter every query
• Next steps
Introduction
Introduction
• Hi, I’m mitcho.
Introduction
• Hi, I’m mitcho.
 • Linguist, coder, teacher.
Introduction
• Hi, I’m mitcho.
 • Linguist, coder, teacher.
• At MIT. Previously at Mozilla. Now
  working with Automattic.
Introduction
• Hi, I’m mitcho.
 • Linguist, coder, teacher.
• At MIT. Previously at Mozilla. Now
    working with Automattic.
•   Programming PHP/MySQL since
    2002?
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.
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
Introduction
Introduction

• Yet Another Related Posts Plugin
Introduction

• Yet Another Related Posts Plugin
 • ...aka YARPP
Introduction

• Yet Another Related Posts Plugin
 • ...aka YARPP
 • As seen on Laughing Squid, ma.tt...
Introduction

• Yet Another Related Posts Plugin
 • ...aka YARPP
 • As seen on Laughing Squid, ma.tt...
 • Over 350k downloads
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
Today

• Introduction
• Loop basics
• Custom queries
 • Method 1: Roll your own query
 • Method 2: Filter every query
• Next steps
The Loop
The Loop

• “The Loop” is the mechanism by
  which posts are called from the
  database and then displayed.
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.
The simplest Loop
       get_header();
       if (have_posts()) :
          while (have_posts()) :
            the_post();
            the_content();
          endwhile;
       endif;
       get_sidebar();
       get_footer();
The simplest Loop
             get_header();
             if (have_posts()) :



             {
                while (have_posts()) :
                  the_post();
“The Loop”        the_content();
                endwhile;
             endif;
             get_sidebar();
             get_footer();
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();
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.
The Loop

       if there are posts
         while there are posts
           get the post
           do stuff with it
         end while
       end if
The Loop

             if there are posts


             {
               while there are posts
                 get the post
“The Loop”
                 do stuff with it
               end while
             end if
The Loop
The Loop

• The Loop is where you can use
  Template Tags.
The Loop

• The Loop is where you can use
 Template Tags.
 • codex.wordpress.org/
   Template_Tags
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.
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/
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/
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/
Every Loop has a query
Every Loop has a query

• Regularly, WordPress chooses the
  right template file and query based on
  your URL.
Every Loop has a query

• Regularly, WordPress chooses the
  right template file and query based on
  your URL.
 • codex.wordpress.org/
   Template_Hierarchy
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
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
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
Today

• Introduction
• Loop basics
• Custom queries
 • Method 1: Roll your own query
 • Method 2: Filter every query
• Next steps
Customizing The
Loop
Customizing The
Loop

• Themes control how information
  is presented...
Customizing The
Loop

• Themes control how information
    is presented...
•   The query controls what
    information is presented.
Custom queries
Custom queries

Possible applications:
Custom queries

Possible applications:
 • Create custom feeds/displays
Custom queries

Possible applications:
 • Create custom feeds/displays
  • ephramzerb.com/projects/feed-
    wrangler/
Custom queries

Possible applications:
 • Create custom feeds/displays
  • ephramzerb.com/projects/feed-
    wrangler/
 • Pull information on other posts
   from within the theme’s Loop
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
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
Today

• Introduction
• Loop basics
• Custom queries
 • Method 1: Roll your own query
 • Method 2: Filter every query
• Next steps
Roll your own query
Roll your own query

EX:
Roll your own query

EX:
 • Pull information on other posts
      from within the theme’s Loop
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.
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]
Roll your own query
Roll your own query

The idea:
Roll your own query

The idea:
 • Create a new WP_Query object.
Roll your own query

The idea:
 • Create a new WP_Query object.
  • Given a $tag...
Roll your own query

The idea:
 • Create a new WP_Query object.
  • Given a $tag...
  • new WP_Query(array('tag'=>
    $tag))
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
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
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
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;
The result:
DEMO:
More about WP_Query
More about WP_Query

Learn more from the Codex:
More about WP_Query

Learn more from the Codex:
 • More information on the
   parameters:
More about WP_Query

Learn more from the Codex:
 • More information on the
   parameters:
  • codex.wordpress.org/
    Template_Tags/query_posts
More about WP_Query

Learn more from the Codex:
 • More information on the
   parameters:
  • codex.wordpress.org/
    Template_Tags/query_posts
 • Tips and examples:
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
Today

• Introduction
• Loop basics
• Custom queries
 • Method 1: Roll your own query
 • Method 2: Filter every query
• Next steps
Filter every query
Filter every query


EX:
Filter every query


EX:
 • Customize what information
      is displayed globally.
Filter every query


EX:
 • Customize what information
      is displayed globally.
 •    Hide all my tweets.
Filter every query
Filter every query


The idea:
Filter every query


The idea:
 • Use the request filter to specify
   that we don’t want results from
   the “tweet” category (#10)
The result:
DEMO
Aside: the tools

Turn up the fire!
 • Firefox getfirefox.com
 • Firebug getfirebug.com
 • FirePHP firephp.org
Aside: the tools

Turn up the fire!
 • Firefox getfirefox.com
 • Firebug getfirebug.com
 • FirePHP firephp.org

         The “Pyrotrinity”
FirePHP

Takes a moment to set up:
FirePHP

Takes a moment to set up:




Use it like this:
Today

• Introduction
• Loop basics
• Custom queries
 • Method 1: Roll your own query
 • Method 2: Filter every query
• Next steps
Next steps
Next steps


Hit the docs:
Next steps


Hit the docs:
 • PHP manual: php.net
Next steps


Hit the docs:
 • PHP manual: php.net
 • Codex: codex.wordpress.org
Next steps


Hit the docs:
 • PHP manual: php.net
 • Codex: codex.wordpress.org
 • The source:
   core.trac.wordpress.org
Next steps


Hit the docs:
 • PHP manual: php.net
 • Codex: codex.wordpress.org
 • The source:
   core.trac.wordpress.org
   • grep it!
Next steps
Next steps

Learn SQL
Next steps

Learn SQL
 • The language that WordPress’s raw
   database calls are in.
Next steps

Learn SQL
 • The language that WordPress’s raw
   database calls are in.
 • It’s really not that scary.
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.
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/
Thank you!
Questions?


Slides will be up on mitcho.com/blog/.
See you at the Genius Bar!

mitcho (Michael 芳貴 Erlewine)
mitcho.com; @mitchoyoshitaka

Mais conteúdo relacionado

Mais procurados

Moo the universe and everything
Moo the universe and everythingMoo the universe and everything
Moo the universe and everythingHenry Van Styn
 
Solr Flair: Search User Interfaces Powered by Apache Solr (ApacheCon US 2009,...
Solr Flair: Search User Interfaces Powered by Apache Solr (ApacheCon US 2009,...Solr Flair: Search User Interfaces Powered by Apache Solr (ApacheCon US 2009,...
Solr Flair: Search User Interfaces Powered by Apache Solr (ApacheCon US 2009,...Erik Hatcher
 
Searching ORM: First Why, Then How
Searching ORM: First Why, Then HowSearching ORM: First Why, Then How
Searching ORM: First Why, Then Howsfarmer10
 
Freebase and the iPhone
Freebase and the iPhoneFreebase and the iPhone
Freebase and the iPhoneAlec Flett
 
[E-Dev-Day 2014][4/16] Review of Eolian, Eo, Bindings, Interfaces and What's ...
[E-Dev-Day 2014][4/16] Review of Eolian, Eo, Bindings, Interfaces and What's ...[E-Dev-Day 2014][4/16] Review of Eolian, Eo, Bindings, Interfaces and What's ...
[E-Dev-Day 2014][4/16] Review of Eolian, Eo, Bindings, Interfaces and What's ...EnlightenmentProject
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developersStoyan Stefanov
 

Mais procurados (7)

Moo the universe and everything
Moo the universe and everythingMoo the universe and everything
Moo the universe and everything
 
API Design
API DesignAPI Design
API Design
 
Solr Flair: Search User Interfaces Powered by Apache Solr (ApacheCon US 2009,...
Solr Flair: Search User Interfaces Powered by Apache Solr (ApacheCon US 2009,...Solr Flair: Search User Interfaces Powered by Apache Solr (ApacheCon US 2009,...
Solr Flair: Search User Interfaces Powered by Apache Solr (ApacheCon US 2009,...
 
Searching ORM: First Why, Then How
Searching ORM: First Why, Then HowSearching ORM: First Why, Then How
Searching ORM: First Why, Then How
 
Freebase and the iPhone
Freebase and the iPhoneFreebase and the iPhone
Freebase and the iPhone
 
[E-Dev-Day 2014][4/16] Review of Eolian, Eo, Bindings, Interfaces and What's ...
[E-Dev-Day 2014][4/16] Review of Eolian, Eo, Bindings, Interfaces and What's ...[E-Dev-Day 2014][4/16] Review of Eolian, Eo, Bindings, Interfaces and What's ...
[E-Dev-Day 2014][4/16] Review of Eolian, Eo, Bindings, Interfaces and What's ...
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 

Destaque

Unit 108 power_point_1
Unit 108 power_point_1Unit 108 power_point_1
Unit 108 power_point_1wirethehouse
 
D Part 15 Hsc & Hse
D  Part 15 Hsc & HseD  Part 15 Hsc & Hse
D Part 15 Hsc & Hseguest2dac56
 
Unit 2 B Safe Working Practices
Unit 2 B Safe Working PracticesUnit 2 B Safe Working Practices
Unit 2 B Safe Working Practicesiarthur
 
Health & safety awareness course
Health & safety awareness courseHealth & safety awareness course
Health & safety awareness courseLee Kennedy
 
15 Inspiring Small Business Quotes to Start Your Day Right
15 Inspiring Small Business Quotes to Start Your Day Right15 Inspiring Small Business Quotes to Start Your Day Right
15 Inspiring Small Business Quotes to Start Your Day RightFivestars
 

Destaque (6)

Rehman Khattak CV
Rehman Khattak CVRehman Khattak CV
Rehman Khattak CV
 
Unit 108 power_point_1
Unit 108 power_point_1Unit 108 power_point_1
Unit 108 power_point_1
 
D Part 15 Hsc & Hse
D  Part 15 Hsc & HseD  Part 15 Hsc & Hse
D Part 15 Hsc & Hse
 
Unit 2 B Safe Working Practices
Unit 2 B Safe Working PracticesUnit 2 B Safe Working Practices
Unit 2 B Safe Working Practices
 
Health & safety awareness course
Health & safety awareness courseHealth & safety awareness course
Health & safety awareness course
 
15 Inspiring Small Business Quotes to Start Your Day Right
15 Inspiring Small Business Quotes to Start Your Day Right15 Inspiring Small Business Quotes to Start Your Day Right
15 Inspiring Small Business Quotes to Start Your Day Right
 

Semelhante a Gettingintotheloop 100123225021-phpapp01

Writing a WordPress Theme - HighEdWeb 2013 #WRK2
Writing a WordPress Theme - HighEdWeb 2013 #WRK2Writing a WordPress Theme - HighEdWeb 2013 #WRK2
Writing a WordPress Theme - HighEdWeb 2013 #WRK2Curtiss Grymala
 
WordPress Themes 101 - PSUWeb13 Workshop
WordPress Themes 101 - PSUWeb13 WorkshopWordPress Themes 101 - PSUWeb13 Workshop
WordPress Themes 101 - PSUWeb13 WorkshopCurtiss Grymala
 
Task 1
Task 1Task 1
Task 1EdiPHP
 
What is the WordPress Loop?
What is the WordPress Loop?What is the WordPress Loop?
What is the WordPress Loop?webdesigncom
 
WordPress Themes 101 - HighEdWeb New England 2013
WordPress Themes 101 - HighEdWeb New England 2013WordPress Themes 101 - HighEdWeb New England 2013
WordPress Themes 101 - HighEdWeb New England 2013Curtiss Grymala
 
ZopeSkel: The past, present and future
ZopeSkel: The past, present and futureZopeSkel: The past, present and future
ZopeSkel: The past, present and futureCristopher Ewing
 
WordPress Themes 101 - dotEduGuru Summit 2013
WordPress Themes 101 - dotEduGuru Summit 2013WordPress Themes 101 - dotEduGuru Summit 2013
WordPress Themes 101 - dotEduGuru Summit 2013Curtiss Grymala
 
Lecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdfLecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdfLê Thưởng
 
Modules Building Presentation
Modules Building PresentationModules Building Presentation
Modules Building Presentationhtyson
 
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...WordCamp Sydney
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)Doris Chen
 
Intro to WordPress theme development
Intro to WordPress theme developmentIntro to WordPress theme development
Intro to WordPress theme developmentThad Allender
 
Hacking Lucene for Custom Search Results
Hacking Lucene for Custom Search ResultsHacking Lucene for Custom Search Results
Hacking Lucene for Custom Search ResultsOpenSource Connections
 
openCV with python
openCV with pythonopenCV with python
openCV with pythonWei-Wen Hsu
 
Customizing the custom loop wordcamp 2012-jeff
Customizing the custom loop   wordcamp 2012-jeffCustomizing the custom loop   wordcamp 2012-jeff
Customizing the custom loop wordcamp 2012-jeffAlexander Sapountzis
 
Polyglot payloads in practice by avlidienbrunn at HackPra
Polyglot payloads in practice by avlidienbrunn at HackPraPolyglot payloads in practice by avlidienbrunn at HackPra
Polyglot payloads in practice by avlidienbrunn at HackPraMathias Karlsson
 
Drupal 8 Deep Dive: Plugin System
Drupal 8 Deep Dive: Plugin SystemDrupal 8 Deep Dive: Plugin System
Drupal 8 Deep Dive: Plugin SystemAcquia
 
Rails and the Apache SOLR Search Engine
Rails and the Apache SOLR Search EngineRails and the Apache SOLR Search Engine
Rails and the Apache SOLR Search EngineDavid Keener
 
Introduction To Moose
Introduction To MooseIntroduction To Moose
Introduction To MooseMike Whitaker
 

Semelhante a Gettingintotheloop 100123225021-phpapp01 (20)

Writing a WordPress Theme - HighEdWeb 2013 #WRK2
Writing a WordPress Theme - HighEdWeb 2013 #WRK2Writing a WordPress Theme - HighEdWeb 2013 #WRK2
Writing a WordPress Theme - HighEdWeb 2013 #WRK2
 
WordPress Themes 101 - PSUWeb13 Workshop
WordPress Themes 101 - PSUWeb13 WorkshopWordPress Themes 101 - PSUWeb13 Workshop
WordPress Themes 101 - PSUWeb13 Workshop
 
Task 1
Task 1Task 1
Task 1
 
What is the WordPress Loop?
What is the WordPress Loop?What is the WordPress Loop?
What is the WordPress Loop?
 
WordPress Themes 101 - HighEdWeb New England 2013
WordPress Themes 101 - HighEdWeb New England 2013WordPress Themes 101 - HighEdWeb New England 2013
WordPress Themes 101 - HighEdWeb New England 2013
 
ZopeSkel: The past, present and future
ZopeSkel: The past, present and futureZopeSkel: The past, present and future
ZopeSkel: The past, present and future
 
WordPress Themes 101 - dotEduGuru Summit 2013
WordPress Themes 101 - dotEduGuru Summit 2013WordPress Themes 101 - dotEduGuru Summit 2013
WordPress Themes 101 - dotEduGuru Summit 2013
 
Lecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdfLecture 03 - JQuery.pdf
Lecture 03 - JQuery.pdf
 
The WordPress Loop
The  WordPress LoopThe  WordPress Loop
The WordPress Loop
 
Modules Building Presentation
Modules Building PresentationModules Building Presentation
Modules Building Presentation
 
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
 
Intro to WordPress theme development
Intro to WordPress theme developmentIntro to WordPress theme development
Intro to WordPress theme development
 
Hacking Lucene for Custom Search Results
Hacking Lucene for Custom Search ResultsHacking Lucene for Custom Search Results
Hacking Lucene for Custom Search Results
 
openCV with python
openCV with pythonopenCV with python
openCV with python
 
Customizing the custom loop wordcamp 2012-jeff
Customizing the custom loop   wordcamp 2012-jeffCustomizing the custom loop   wordcamp 2012-jeff
Customizing the custom loop wordcamp 2012-jeff
 
Polyglot payloads in practice by avlidienbrunn at HackPra
Polyglot payloads in practice by avlidienbrunn at HackPraPolyglot payloads in practice by avlidienbrunn at HackPra
Polyglot payloads in practice by avlidienbrunn at HackPra
 
Drupal 8 Deep Dive: Plugin System
Drupal 8 Deep Dive: Plugin SystemDrupal 8 Deep Dive: Plugin System
Drupal 8 Deep Dive: Plugin System
 
Rails and the Apache SOLR Search Engine
Rails and the Apache SOLR Search EngineRails and the Apache SOLR Search Engine
Rails and the Apache SOLR Search Engine
 
Introduction To Moose
Introduction To MooseIntroduction To Moose
Introduction To Moose
 

Último

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 

Último (20)

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 

Gettingintotheloop 100123225021-phpapp01

  • 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
  • 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
  • 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
  • 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
  • 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
  • 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.
  • 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;
  • 68. DEMO:
  • 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
  • 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.
  • 82. Filter every query The idea: • Use the request filter to specify that we don’t want results from the “tweet” category (#10)
  • 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”
  • 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
  • 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!
  • 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

Notas do Editor

  1. \n
  2. We have a good deal of content to cover.\nI may defer questions to the end. I can stick around later to answer questions too.\n
  3. \n
  4. We have a good deal of content to cover.\nI may defer questions to the end. I can stick around later to answer questions too.\n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. My WP claim to fame\n
  12. My WP claim to fame\n
  13. My WP claim to fame\n
  14. My WP claim to fame\n
  15. My WP claim to fame\n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. Knowing just this will help you modify themes intelligently.\n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. the source - get it local, grep on it.\n
  90. the source - get it local, grep on it.\n
  91. the source - get it local, grep on it.\n
  92. the source - get it local, grep on it.\n
  93. the source - get it local, grep on it.\n
  94. \n
  95. \n
  96. \n
  97. \n
  98. \n
  99. \n