Be The Loop: WordCamp Chicago 2017
by
Allison Tarr
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
Be The Loop You Want To See In The World
Slide 2
Slide 2 text
H’allo there… I’m Allison. ◎ Feminist. Writer. Lover of guacamole. ◎ Front-end developer at WebDevStudios ◎ @allisonplus
Slide 3
Slide 3 text
We’re going to go over... ◎ What is The Loop? ◎ The power of customizing WP_Query(); ◎ Examples of customizations
Slide 4
Slide 4 text
1. AHHHHHHHHH! The Loop. Let’s start with taking a deep breath.
Slide 5
Slide 5 text
“ The loop is PHP code used by WordPress to display posts. https://codex.wordpress.org/The_Loop
Slide 6
Slide 6 text
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!
Slide 7
Slide 7 text
No content
Slide 8
Slide 8 text
The Loop is Lovely because it... ◎ Saves time ◎ Keeps your code condensed & tidy ◎ Efficient!
Slide 9
Slide 9 text
No content
Slide 10
Slide 10 text
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)
Slide 11
Slide 11 text
No content
Slide 12
Slide 12 text
No content
Slide 13
Slide 13 text
What can the Loop output? ◎ Template Tags ◎ HTML your content is wrapped in ◎ Customizations (if any)
Slide 14
Slide 14 text
No content
Slide 15
Slide 15 text
Every Loop has a query. The query is the request for the information your Loop will have access to.
Slide 16
Slide 16 text
In the regular ol’ Loop... WordPress automatically loads a global variable to get the appropriate content.
Slide 17
Slide 17 text
What if I want more? What if that loop isn’t good enough?
Slide 18
Slide 18 text
WP_Query() Blah blah blah. https://codex.wordpress.org/Class_Reference/WP_Query
Slide 19
Slide 19 text
There’s a few different ways to go about this ● WP_Query() ● pre_get_posts() ● query_posts()
Slide 20
Slide 20 text
Custom Post Types For use within plugins &/or widgets Posts by multiple authors Why would we need a custom query?
Slide 21
Slide 21 text
WP_Query Ingredients ◎ Define what you’re asking for ◎ Arguments for the query ◎ The Loop ◎ Leave no trace.
Slide 22
Slide 22 text
No content
Slide 23
Slide 23 text
Arguments Define it. Loop Clean-up!
Slide 24
Slide 24 text
Arguments Your arguments feed the query. The query feeds The Loop. https://codex.wordpress.org/Class_Reference/WP_Query#Parameters
Slide 25
Slide 25 text
No content
Slide 26
Slide 26 text
No content
Slide 27
Slide 27 text
Define Your Query $fancy_new_query = new WP_Query( $args );
Slide 28
Slide 28 text
The Loop
Slide 29
Slide 29 text
Leave No Trace.
Slide 30
Slide 30 text
wp_reset_postdata(); Resets the global $post data we’ve been messing with after a custom query. https://codex.wordpress.org/wp_reset_postdata
Slide 31
Slide 31 text
No content
Slide 32
Slide 32 text
Display a sticky post I can do anything?! Grabbing a random selection from a Custom Post Type
Slide 33
Slide 33 text
Random Team Member
Slide 34
Slide 34 text
Display a Sticky Post
Slide 35
Slide 35 text
Thanks! Any questions? Come hang out with me online at: ◎ @allisonplus ◎
[email protected]
◎ allisontarr.com Presentation template by SlidesCarnival