Slide 1

Slide 1 text

The WordPress Loop Giustino Borzacchiello / WordPress Meetup Milano - January 2016

Slide 2

Slide 2 text

The standard Loop

Slide 3

Slide 3 text

The standard Loop What’s The Loop?

Slide 4

Slide 4 text

The standard Loop “The Loop is PHP code used by WordPress to display posts.” https://codex.wordpress.org/The_Loop

Slide 5

Slide 5 text

The standard Loop “The Loop is PHP code used by WordPress to display posts.” https://codex.wordpress.org/The_Loop

Slide 6

Slide 6 text

The standard Loop “The Loop is PHP code used by WordPress to display posts.” https://codex.wordpress.org/The_Loop

Slide 7

Slide 7 text

The standard Loop Post list

Slide 8

Slide 8 text

The standard Loop Single post/page

Slide 9

Slide 9 text

The standard Loop “Mullet” loop

Slide 10

Slide 10 text

The standard Loop Random post widget

Slide 11

Slide 11 text

The standard Loop Related posts

Slide 12

Slide 12 text

The standard Loop The Loop breakdown

Slide 13

Slide 13 text

Slide 14

Slide 14 text

Slide 15

Slide 15 text

Slide 16

Slide 16 text

Slide 17

Slide 17 text

... while ( have_posts() ): the_post();

endwhile; else: // No post found endif;

Slide 18

Slide 18 text

... while ( have_posts() ): the_post();

endwhile; else: // No post found endif; Template tags

Slide 19

Slide 19 text

Slide 20

Slide 20 text

Slide 21

Slide 21 text

The standard Loop Single Loop

Slide 22

Slide 22 text

if ( have_posts() ): while ( have_posts() ): the_post();

endwhile; endif;

Slide 23

Slide 23 text

The standard Loop “Mullet” Loop

Slide 24

Slide 24 text

The standard Loop 1 2 3 4 5

Slide 25

Slide 25 text

Slide 26

Slide 26 text

The standard Loop Random posts Loop

Slide 27

Slide 27 text

'rand']); if ( $rand_query->have_posts() ): while ( $rand_query->have_posts() ): $rand_query->the_post(); the_title(); endwhile; endif; wp_reset_postdata();

Slide 28

Slide 28 text

'rand']); if ( $rand_query->have_posts() ): while ( $rand_query->have_posts() ): $rand_query->the_post(); the_title(); endwhile; endif; wp_reset_postdata();

Slide 29

Slide 29 text

The standard Loop Useful references

Slide 30

Slide 30 text

The standard Loop The loop and template tags https://developer.wordpress.org/themes/basics/the-loop/ https://codex.wordpress.org/The_Loop https://codex.wordpress.org/The_Loop_in_Action

Slide 31

Slide 31 text

The standard Loop Try to find and understand the loop in this theme https://github.com/WordPress/twentysixteen

Slide 32

Slide 32 text

The standard Loop How does WordPress find what posts to show? https://developer.wordpress.org/themes/basics/template-hierarchy/

Slide 33

Slide 33 text

The standard Loop WP_Query https://codex.wordpress.org/Class_Reference/WP_Query

Slide 34

Slide 34 text

The standard Loop thank you @jubstuff borzacchiello.it

Slide 35

Slide 35 text

The standard Loop Extra: related posts loop

Slide 36

Slide 36 text

if ( have_posts() ): while ( have_posts() ): the_post(); // EXERCISE! Insert here template tags $rel_query = new WP_Query([ 'category__in' => wp_get_post_categories($post->ID), 'post__not_in' => [$post->ID], 'posts_per_page' => 3, ]); // EXERCISE! Insert here $rel_query loop! endwhile; endif;

Slide 37

Slide 37 text

Images https://www.flickr.com/photos/nkphillips/2984667077/ https://www.flickr.com/photos/jeremybrooks/2214481087/ https://www.flickr.com/photos/benjaminbeard/5642453196/ https://www.flickr.com/photos/jpestana/16315778523/ https://www.flickr.com/photos/xroper7/19998325086/ https://www.flickr.com/photos/katsrcool/16912193533/ https://www.flickr.com/photos/15609463@N03/9848807935/ https://www.flickr.com/photos/adamfowler/4841559945/ https://www.flickr.com/photos/donald_gunn/15340138404/ https://www.flickr.com/photos/trevira1/8218299403/