Be The Loop: WordCamp Chicago 2017

Be The Loop: WordCamp Chicago 2017

We live inside the boundaries of The Loop. As an intrinsic part of WordPress, does it mystify you? Are you feeling a bit stuck in there? Want to expand its limits? In this talk, we’ll go over what the loop is all about as well as learn more about the creative possibilities of customizing what data you’re retrieving through the use of WP_Query to write your very own queries and loops.

2b951ffdb5c1d1a40e219a719b29cf8b?s=128

Allison Tarr

April 29, 2017
Tweet

Transcript

  1. Be The Loop You Want To See In The World

  2. H’allo there… I’m Allison. ◎ Feminist. Writer. Lover of guacamole.

    ◎ Front-end developer at WebDevStudios ◎ @allisonplus
  3. We’re going to go over... ◎ What is The Loop?

    ◎ The power of customizing WP_Query(); ◎ Examples of customizations
  4. 1. AHHHHHHHHH! The Loop. Let’s start with taking a deep

    breath.
  5. “ The loop is PHP code used by WordPress to

    display posts. https://codex.wordpress.org/The_Loop
  6. What does it do? ◎ It’s the thing that goes

    and gets your content from the database. ◎ Loops over posts to bring in data. ◎ Makes our lives easier!
  7. None
  8. The Loop is Lovely because it... ◎ Saves time ◎

    Keeps your code condensed & tidy ◎ Efficient!
  9. None
  10. The Loop in real talk. If there are any posts

    And only while there are still posts, Give me the post! (if not, do something else)
  11. None
  12. None
  13. What can the Loop output? ◎ Template Tags ◎ HTML

    your content is wrapped in ◎ Customizations (if any)
  14. None
  15. Every Loop has a query. The query is the request

    for the information your Loop will have access to.
  16. In the regular ol’ Loop... WordPress automatically loads a global

    variable to get the appropriate content.
  17. What if I want more? What if that loop isn’t

    good enough?
  18. WP_Query() Blah blah blah. https://codex.wordpress.org/Class_Reference/WP_Query

  19. There’s a few different ways to go about this •

    WP_Query() • pre_get_posts() • query_posts()
  20. Custom Post Types For use within plugins &/or widgets Posts

    by multiple authors Why would we need a custom query?
  21. WP_Query Ingredients ◎ Define what you’re asking for ◎ Arguments

    for the query ◎ The Loop ◎ Leave no trace.
  22. None
  23. Arguments Define it. Loop Clean-up!

  24. Arguments Your arguments feed the query. The query feeds The

    Loop. https://codex.wordpress.org/Class_Reference/WP_Query#Parameters
  25. None
  26. None
  27. Define Your Query $fancy_new_query = new WP_Query( $args );

  28. The Loop

  29. Leave No Trace.

  30. wp_reset_postdata(); Resets the global $post data we’ve been messing with

    after a custom query. https://codex.wordpress.org/wp_reset_postdata
  31. None
  32. Display a sticky post I can do anything?! Grabbing a

    random selection from a Custom Post Type
  33. Random Team Member

  34. Display a Sticky Post

  35. Thanks! Any questions? Come hang out with me online at:

    ◎ @allisonplus ◎ hello@allisontarr.com ◎ allisontarr.com Presentation template by SlidesCarnival