SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Kürzlich hochgeladen (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

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

Hinweis der Redaktion

  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