Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
The WordPress Loop
Search
Giustino Borzacchiello
January 12, 2016
Technology
1
480
The WordPress Loop
Giustino Borzacchiello
January 12, 2016
Tweet
Share
More Decks by Giustino Borzacchiello
See All by Giustino Borzacchiello
Cos'è Gutenberg?
justb
1
230
The WordPress Economy
justb
0
250
Vagrant: why and how
justb
0
74
10* useful WordPress function (* maybe more) - wctrn
justb
0
510
10 Useful WordPress functions (and maybe more)
justb
4
520
MapReduce for clone detection
justb
0
60
Featured posts with thumbnails
justb
0
33
Other Decks in Technology
See All in Technology
Redmineの意外と知らない便利機能 (Redmine 6.0対応版)
vividtone
0
1.3k
OSMnx Galleryの紹介
mopinfish
0
150
大規模PaaSにおける監視基盤の構築と効率化の道のり
lycorptech_jp
PRO
0
180
mnt_data_とは?ChatGPTコード実行環境を深堀りしてみた
icck
0
210
AIコードエディタは開発を変えるか?Cursorをチームに導入して1ヶ月経った本音
ota1022
1
710
ローカル環境でAIを動かそう!
falken
PRO
1
170
NW運用の工夫と発明
recuraki
1
800
Contract One Dev Group 紹介資料
sansan33
PRO
0
6k
RDRA3.0を知ろう
kanzaki
2
440
プラットフォームとしての Datadog / Datadog as Platforms
aoto
PRO
1
340
Java 30周年記念! Javaの30年をふりかえる
skrb
2
1.7k
実践Kafka Streams 〜イベント駆動型アーキテクチャを添えて〜
joker1007
1
590
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
52
7.6k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
750
Gamification - CAS2011
davidbonilla
81
5.3k
How to train your dragon (web standard)
notwaldorf
92
6k
Writing Fast Ruby
sferik
628
61k
VelocityConf: Rendering Performance Case Studies
addyosmani
329
24k
GraphQLとの向き合い方2022年版
quramy
46
14k
What's in a price? How to price your products and services
michaelherold
245
12k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
180
53k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
Scaling GitHub
holman
459
140k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
357
30k
Transcript
The WordPress Loop Giustino Borzacchiello / WordPress Meetup Milano -
January 2016
The standard Loop
The standard Loop What’s The Loop?
The standard Loop “The Loop is PHP code used by
WordPress to display posts.” https://codex.wordpress.org/The_Loop
The standard Loop “The Loop is PHP code used by
WordPress to display posts.” https://codex.wordpress.org/The_Loop
The standard Loop “The Loop is PHP code used by
WordPress to display posts.” https://codex.wordpress.org/The_Loop
The standard Loop Post list
The standard Loop Single post/page
The standard Loop “Mullet” loop
The standard Loop Random post widget
The standard Loop Related posts
The standard Loop The Loop breakdown
<?php if ( have_posts() ): while ( have_posts() ): the_post();
// Single post endwhile; else: // No post found endif;
<?php if ( have_posts() ): while ( have_posts() ): the_post();
// Single post endwhile; else: // No post found endif;
<?php if ( have_posts() ): while ( have_posts() ): the_post();
// Single post endwhile; else: // No post found endif;
<?php if ( have_posts() ): while ( have_posts() ): the_post();
// Single post endwhile; else: // No post found endif;
... while ( have_posts() ): the_post(); <h2><?php the_title(); ?></h2> <?php
the_excerpt(); ?> endwhile; else: // No post found endif;
... while ( have_posts() ): the_post(); <h2><?php the_title(); ?></h2> <?php
the_excerpt(); ?> endwhile; else: // No post found endif; Template tags
<?php if ( have_posts() ): while ( have_posts() ): the_post();
// Single post endwhile; else: // No post found endif;
<?php if ( have_posts() ): while ( have_posts() ): the_post();
// Single post endwhile; else: // No post found endif;
The standard Loop Single Loop
if ( have_posts() ): while ( have_posts() ): the_post(); <h2><?php
the_title(); ?></h2> <?php the_content(); ?> endwhile; endif;
The standard Loop “Mullet” Loop
The standard Loop 1 2 3 4 5
<?php if ( have_posts() ): $count = 0; while (
have_posts() ): the_post(); if( 0 === $count ) { // first post } else { // other posts } $count += 1; endwhile; endif;
The standard Loop Random posts Loop
<?php $rand_query = new WP_Query(['orderby' => 'rand']); if ( $rand_query->have_posts()
): while ( $rand_query->have_posts() ): $rand_query->the_post(); the_title(); endwhile; endif; wp_reset_postdata();
<?php $rand_query = new WP_Query(['orderby' => 'rand']); if ( $rand_query->have_posts()
): while ( $rand_query->have_posts() ): $rand_query->the_post(); the_title(); endwhile; endif; wp_reset_postdata();
The standard Loop Useful references
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
The standard Loop Try to find and understand the loop
in this theme https://github.com/WordPress/twentysixteen
The standard Loop How does WordPress find what posts to
show? https://developer.wordpress.org/themes/basics/template-hierarchy/
The standard Loop WP_Query https://codex.wordpress.org/Class_Reference/WP_Query
The standard Loop thank you @jubstuff borzacchiello.it
The standard Loop Extra: related posts loop
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;
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/