SlideShare une entreprise Scribd logo
1  sur  15
Télécharger pour lire hors ligne
THE LOOP
        JAKE SPURLOCK
@WHYISJAKE JAKESPURLOCK.COM
DEVELOPERS IN
 THE HOUSE?
OVERVIEW


INTRODUCE THE LOOP

BASIC TEMPLATE TAGS

CUSTOM QUERIES

MULTIPLE LOOPS PAGE

CUSTOM POST TYPES
GET STARTED...
WHY NOT JUST LOOK AT CODE EH?
SIMPLEST INDEX PAGE

<?PHP

     IF (HAVE_POSTS()) :

       WHILE (HAVE_POSTS()) :

          THE_POST();

          THE_CONTENT();

       ENDWHILE;

     ENDIF;

?>
TEMPLATE TAGS
.:THE BREAD AND BUTTER OF THEME DESIGNERS:.
TEMPLATE TAGS

THE_CONTENT()         THE_META();

THE_TITLE()           THE_ID()

THE_PERMALINK()       THE_POST_THUMBNAIL()

THE_CATEGORY()        THE_AUTHOR()

THE_TAGS()            THE_SHORTLINK()

THE_DATE()            EDIT_POST_LINK()
                      CODEX.WORDPRESS.ORG/TEMPLATE_TAGS
THE_EXCERPT()
CUSTOM QUERIES
QUERY_POSTS
    VS.
 GET_POSTS
QUERY_POSTS



WHEN YOU WANT TO CHANGE THE MAIN LOOP

EXCLUDE CATEGORIES FROM MAIN LOOP

SHOW POSTS FROM ONLY ONE CATEGORY.
IMPORTANT NOTE

THE QUERY_POSTS FUNCTION IS INTENDED TO BE USED
TO MODIFY THE MAIN PAGE LOOP ONLY. IT IS NOT
INTENDED AS A MEANS TO CREATE SECONDARY LOOPS
ON THE PAGE. IF YOU WANT TO CREATE SEPARATE
LOOPS OUTSIDE OF THE MAIN ONE, YOU SHOULD USE
GET_POSTS() INSTEAD. USE OF QUERY_POSTS ON LOOPS
OTHER THAN THE MAIN ONE CAN RESULT IN YOUR MAIN
LOOP BECOMING INCORRECT AND POSSIBLY DISPLAYING
THINGS THAT YOU WERE NOT EXPECTING.

THE QUERY_POSTS FUNCTION OVERRIDES AND
REPLACES THE MAIN QUERY FOR THE PAGE. TO SAVE
YOUR SANITY, DO NOT USE IT FOR ANY OTHER PURPOSE.
<?php

//The
Query
query_posts('posts_per_page=5');

//The
Loop
if
(
have_posts()
)
:
while
(
have_posts()
)
:

the_post();

..
endwhile;
else:

..
endif;

//Reset
Query
wp_reset_query();

?>
CUSTOM POST TYPES?
QUERY_POSTS WITH
       CUSTOM POST TYPES



QUERY_POSTS( 'POST_TYPE=NAME 0F POST TYPE');

QUERY_POSTS(ARRAY('POST_TYPE' => ARRAY('POST',
'MOVIES')));
PLUGIN?

ADD_FILTER( 'PRE_GET_POSTS', 'MY_GET_POSTS' );

FUNCTION MY_GET_POSTS( $QUERY ) {

!  IF ( IS_HOME() && FALSE == $QUERY-
>QUERY_VARS['SUPPRESS_FILTERS'] )
!  !     $QUERY->SET( 'POST_TYPE', ARRAY( 'POST', 'PAGE', 'ALBUM',
'MOVIE', 'QUOTE', 'ATTACHMENT' ) );

!   RETURN $QUERY;
}




                                         VIA
JUSTIN
TADLOCK

Contenu connexe

Similaire à The Loop: An Introduction to WordPress Template Tags and Custom Queries

WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practicesmarkparolisi
 
PSD to WordPress
PSD to WordPressPSD to WordPress
PSD to WordPressNile Flores
 
WebMatrix 100-level presentation
WebMatrix 100-level presentationWebMatrix 100-level presentation
WebMatrix 100-level presentationAlice Pang
 
Various Ways of Using WordPress
Various Ways of Using WordPressVarious Ways of Using WordPress
Various Ways of Using WordPressNick La
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Mike Schinkel
 
Word press interview question and answer tops technologies
Word press interview question and answer   tops technologiesWord press interview question and answer   tops technologies
Word press interview question and answer tops technologiesTOPS Technologies
 
Word press templates
Word press templatesWord press templates
Word press templatesDan Phiffer
 
Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Paul Bearne
 
Introduction to WordPress Theme Development
Introduction to WordPress Theme DevelopmentIntroduction to WordPress Theme Development
Introduction to WordPress Theme DevelopmentSitdhibong Laokok
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's CodeWildan Maulana
 
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway ichikaway
 
The Way to Theme Enlightenment
The Way to Theme EnlightenmentThe Way to Theme Enlightenment
The Way to Theme EnlightenmentAmanda Giles
 
Design and Development performance considerations
Design and Development performance considerationsDesign and Development performance considerations
Design and Development performance considerationsElaine Van Bergen
 
How to Re-Order wordpress posts by custom field
How to Re-Order wordpress posts by custom fieldHow to Re-Order wordpress posts by custom field
How to Re-Order wordpress posts by custom fieldYourBlogCoach1
 
SEO Method For Blogger
SEO Method For BloggerSEO Method For Blogger
SEO Method For BloggerSeo Indonesia
 
SEO Mistake From Blogger
SEO Mistake From BloggerSEO Mistake From Blogger
SEO Mistake From BloggerSeo Indonesia
 
Alternative discovery and_seo_fee-stephan_spencer
Alternative discovery and_seo_fee-stephan_spencerAlternative discovery and_seo_fee-stephan_spencer
Alternative discovery and_seo_fee-stephan_spencerzachbrowne
 

Similaire à The Loop: An Introduction to WordPress Template Tags and Custom Queries (20)

WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practices
 
PSD to WordPress
PSD to WordPressPSD to WordPress
PSD to WordPress
 
Wordpress(css,php,js,ajax)
Wordpress(css,php,js,ajax)Wordpress(css,php,js,ajax)
Wordpress(css,php,js,ajax)
 
WebMatrix 100-level presentation
WebMatrix 100-level presentationWebMatrix 100-level presentation
WebMatrix 100-level presentation
 
Various Ways of Using WordPress
Various Ways of Using WordPressVarious Ways of Using WordPress
Various Ways of Using WordPress
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
 
Word press interview question and answer tops technologies
Word press interview question and answer   tops technologiesWord press interview question and answer   tops technologies
Word press interview question and answer tops technologies
 
Word press templates
Word press templatesWord press templates
Word press templates
 
Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919
 
Introduction to WordPress Theme Development
Introduction to WordPress Theme DevelopmentIntroduction to WordPress Theme Development
Introduction to WordPress Theme Development
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
 
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
Tips of CakePHP and MongoDB - Cakefest2011 ichikaway
 
The Way to Theme Enlightenment
The Way to Theme EnlightenmentThe Way to Theme Enlightenment
The Way to Theme Enlightenment
 
Design and Development performance considerations
Design and Development performance considerationsDesign and Development performance considerations
Design and Development performance considerations
 
How to Re-Order wordpress posts by custom field
How to Re-Order wordpress posts by custom fieldHow to Re-Order wordpress posts by custom field
How to Re-Order wordpress posts by custom field
 
SEO For WordPress
SEO For WordPressSEO For WordPress
SEO For WordPress
 
SEO Mistakes
SEO MistakesSEO Mistakes
SEO Mistakes
 
SEO Method For Blogger
SEO Method For BloggerSEO Method For Blogger
SEO Method For Blogger
 
SEO Mistake From Blogger
SEO Mistake From BloggerSEO Mistake From Blogger
SEO Mistake From Blogger
 
Alternative discovery and_seo_fee-stephan_spencer
Alternative discovery and_seo_fee-stephan_spencerAlternative discovery and_seo_fee-stephan_spencer
Alternative discovery and_seo_fee-stephan_spencer
 

Plus de Jake Spurlock

Monetize All the Things
Monetize All the ThingsMonetize All the Things
Monetize All the ThingsJake Spurlock
 
Building Javascript Apps with the WordPress JSON API – LoopConf 2015
Building Javascript Apps with the WordPress JSON API – LoopConf 2015Building Javascript Apps with the WordPress JSON API – LoopConf 2015
Building Javascript Apps with the WordPress JSON API – LoopConf 2015Jake Spurlock
 
How Maker Faire is Using WordPress
How Maker Faire is Using WordPressHow Maker Faire is Using WordPress
How Maker Faire is Using WordPressJake Spurlock
 
Google Glass, Hands On
Google Glass, Hands OnGoogle Glass, Hands On
Google Glass, Hands OnJake Spurlock
 
WordPress Beginner Track
WordPress Beginner TrackWordPress Beginner Track
WordPress Beginner TrackJake Spurlock
 
PhotoBlogging With WordPress
PhotoBlogging With WordPressPhotoBlogging With WordPress
PhotoBlogging With WordPressJake Spurlock
 
Twitter Presentation
Twitter PresentationTwitter Presentation
Twitter PresentationJake Spurlock
 

Plus de Jake Spurlock (9)

Monetize All the Things
Monetize All the ThingsMonetize All the Things
Monetize All the Things
 
Building Javascript Apps with the WordPress JSON API – LoopConf 2015
Building Javascript Apps with the WordPress JSON API – LoopConf 2015Building Javascript Apps with the WordPress JSON API – LoopConf 2015
Building Javascript Apps with the WordPress JSON API – LoopConf 2015
 
How Maker Faire is Using WordPress
How Maker Faire is Using WordPressHow Maker Faire is Using WordPress
How Maker Faire is Using WordPress
 
Google Glass, Hands On
Google Glass, Hands OnGoogle Glass, Hands On
Google Glass, Hands On
 
WordCamp Vegas 2010
WordCamp Vegas 2010WordCamp Vegas 2010
WordCamp Vegas 2010
 
WordPress Beginner Track
WordPress Beginner TrackWordPress Beginner Track
WordPress Beginner Track
 
Logo Design
Logo DesignLogo Design
Logo Design
 
PhotoBlogging With WordPress
PhotoBlogging With WordPressPhotoBlogging With WordPress
PhotoBlogging With WordPress
 
Twitter Presentation
Twitter PresentationTwitter Presentation
Twitter Presentation
 

Dernier

AI and Design Vol. 2: Navigating the New Frontier - Morgenbooster
AI and Design Vol. 2: Navigating the New Frontier - MorgenboosterAI and Design Vol. 2: Navigating the New Frontier - Morgenbooster
AI and Design Vol. 2: Navigating the New Frontier - Morgenbooster1508 A/S
 
Giulio Michelon, Founder di @Belka – “Oltre le Stime: Sviluppare una Mentalit...
Giulio Michelon, Founder di @Belka – “Oltre le Stime: Sviluppare una Mentalit...Giulio Michelon, Founder di @Belka – “Oltre le Stime: Sviluppare una Mentalit...
Giulio Michelon, Founder di @Belka – “Oltre le Stime: Sviluppare una Mentalit...Associazione Digital Days
 
Piece by Piece Magazine
Piece by Piece Magazine                      Piece by Piece Magazine
Piece by Piece Magazine CharlottePulte
 
LIGHTSCAPES: HOW MIGHT WE DESIGN AN INCLUSIVE AND ACCESSIBLE CLASSICAL CONCER...
LIGHTSCAPES: HOW MIGHT WE DESIGN AN INCLUSIVE AND ACCESSIBLE CLASSICAL CONCER...LIGHTSCAPES: HOW MIGHT WE DESIGN AN INCLUSIVE AND ACCESSIBLE CLASSICAL CONCER...
LIGHTSCAPES: HOW MIGHT WE DESIGN AN INCLUSIVE AND ACCESSIBLE CLASSICAL CONCER...Pranav Subramanian
 
guest bathroom white and bluesssssssssss
guest bathroom white and bluesssssssssssguest bathroom white and bluesssssssssss
guest bathroom white and bluesssssssssssNadaMohammed714321
 
Karim apartment ideas 01 ppppppppppppppp
Karim apartment ideas 01 pppppppppppppppKarim apartment ideas 01 ppppppppppppppp
Karim apartment ideas 01 pppppppppppppppNadaMohammed714321
 
simpson-lee_house_dt20ajshsjsjsjsjj15.pdf
simpson-lee_house_dt20ajshsjsjsjsjj15.pdfsimpson-lee_house_dt20ajshsjsjsjsjj15.pdf
simpson-lee_house_dt20ajshsjsjsjsjj15.pdfLucyBonelli
 
CAPITAL GATE CASE STUDY -regional case study.pdf
CAPITAL GATE CASE STUDY -regional case study.pdfCAPITAL GATE CASE STUDY -regional case study.pdf
CAPITAL GATE CASE STUDY -regional case study.pdfAlasAlthaher
 
STITCH: HOW MIGHT WE PROMOTE AN EQUITABLE AND INCLUSIVE URBAN LIFESTYLE PRIOR...
STITCH: HOW MIGHT WE PROMOTE AN EQUITABLE AND INCLUSIVE URBAN LIFESTYLE PRIOR...STITCH: HOW MIGHT WE PROMOTE AN EQUITABLE AND INCLUSIVE URBAN LIFESTYLE PRIOR...
STITCH: HOW MIGHT WE PROMOTE AN EQUITABLE AND INCLUSIVE URBAN LIFESTYLE PRIOR...Pranav Subramanian
 
guest bathroom white and blue ssssssssss
guest bathroom white and blue ssssssssssguest bathroom white and blue ssssssssss
guest bathroom white and blue ssssssssssNadaMohammed714321
 
ALISIA: HOW MIGHT WE ACHIEVE HIGH ENVIRONMENTAL PERFORMANCE WHILE MAINTAINING...
ALISIA: HOW MIGHT WE ACHIEVE HIGH ENVIRONMENTAL PERFORMANCE WHILE MAINTAINING...ALISIA: HOW MIGHT WE ACHIEVE HIGH ENVIRONMENTAL PERFORMANCE WHILE MAINTAINING...
ALISIA: HOW MIGHT WE ACHIEVE HIGH ENVIRONMENTAL PERFORMANCE WHILE MAINTAINING...Pranav Subramanian
 
TIMBRE: HOW MIGHT WE REMEDY MUSIC DESERTS AND FACILITATE GROWTH OF A MUSICAL ...
TIMBRE: HOW MIGHT WE REMEDY MUSIC DESERTS AND FACILITATE GROWTH OF A MUSICAL ...TIMBRE: HOW MIGHT WE REMEDY MUSIC DESERTS AND FACILITATE GROWTH OF A MUSICAL ...
TIMBRE: HOW MIGHT WE REMEDY MUSIC DESERTS AND FACILITATE GROWTH OF A MUSICAL ...Pranav Subramanian
 
10 must-have Chrome extensions for designers
10 must-have Chrome extensions for designers10 must-have Chrome extensions for designers
10 must-have Chrome extensions for designersPixeldarts
 
Making and Unmaking of Chandigarh - A City of Two Plans2-4-24.ppt
Making and Unmaking of Chandigarh - A City of Two Plans2-4-24.pptMaking and Unmaking of Chandigarh - A City of Two Plans2-4-24.ppt
Making and Unmaking of Chandigarh - A City of Two Plans2-4-24.pptJIT KUMAR GUPTA
 
10 Best WordPress Plugins to make the website effective in 2024
10 Best WordPress Plugins to make the website effective in 202410 Best WordPress Plugins to make the website effective in 2024
10 Best WordPress Plugins to make the website effective in 2024digital learning point
 
Interior Design for Office a cura di RMG Project Studio
Interior Design for Office a cura di RMG Project StudioInterior Design for Office a cura di RMG Project Studio
Interior Design for Office a cura di RMG Project StudioRMG Project Studio
 
FW25-26 Knit Cut & Sew Trend Book Peclers Paris
FW25-26 Knit Cut & Sew Trend Book Peclers ParisFW25-26 Knit Cut & Sew Trend Book Peclers Paris
FW25-26 Knit Cut & Sew Trend Book Peclers ParisPeclers Paris
 
Niintendo Wii Presentation Template.pptx
Niintendo Wii Presentation Template.pptxNiintendo Wii Presentation Template.pptx
Niintendo Wii Presentation Template.pptxKevinYaelJimnezSanti
 
Map of St. Louis Parks
Map of St. Louis Parks                              Map of St. Louis Parks
Map of St. Louis Parks CharlottePulte
 
Imagist3D Architectural and Interior Rendering Portfolio
Imagist3D Architectural and Interior Rendering PortfolioImagist3D Architectural and Interior Rendering Portfolio
Imagist3D Architectural and Interior Rendering PortfolioAlinaLau2
 

Dernier (20)

AI and Design Vol. 2: Navigating the New Frontier - Morgenbooster
AI and Design Vol. 2: Navigating the New Frontier - MorgenboosterAI and Design Vol. 2: Navigating the New Frontier - Morgenbooster
AI and Design Vol. 2: Navigating the New Frontier - Morgenbooster
 
Giulio Michelon, Founder di @Belka – “Oltre le Stime: Sviluppare una Mentalit...
Giulio Michelon, Founder di @Belka – “Oltre le Stime: Sviluppare una Mentalit...Giulio Michelon, Founder di @Belka – “Oltre le Stime: Sviluppare una Mentalit...
Giulio Michelon, Founder di @Belka – “Oltre le Stime: Sviluppare una Mentalit...
 
Piece by Piece Magazine
Piece by Piece Magazine                      Piece by Piece Magazine
Piece by Piece Magazine
 
LIGHTSCAPES: HOW MIGHT WE DESIGN AN INCLUSIVE AND ACCESSIBLE CLASSICAL CONCER...
LIGHTSCAPES: HOW MIGHT WE DESIGN AN INCLUSIVE AND ACCESSIBLE CLASSICAL CONCER...LIGHTSCAPES: HOW MIGHT WE DESIGN AN INCLUSIVE AND ACCESSIBLE CLASSICAL CONCER...
LIGHTSCAPES: HOW MIGHT WE DESIGN AN INCLUSIVE AND ACCESSIBLE CLASSICAL CONCER...
 
guest bathroom white and bluesssssssssss
guest bathroom white and bluesssssssssssguest bathroom white and bluesssssssssss
guest bathroom white and bluesssssssssss
 
Karim apartment ideas 01 ppppppppppppppp
Karim apartment ideas 01 pppppppppppppppKarim apartment ideas 01 ppppppppppppppp
Karim apartment ideas 01 ppppppppppppppp
 
simpson-lee_house_dt20ajshsjsjsjsjj15.pdf
simpson-lee_house_dt20ajshsjsjsjsjj15.pdfsimpson-lee_house_dt20ajshsjsjsjsjj15.pdf
simpson-lee_house_dt20ajshsjsjsjsjj15.pdf
 
CAPITAL GATE CASE STUDY -regional case study.pdf
CAPITAL GATE CASE STUDY -regional case study.pdfCAPITAL GATE CASE STUDY -regional case study.pdf
CAPITAL GATE CASE STUDY -regional case study.pdf
 
STITCH: HOW MIGHT WE PROMOTE AN EQUITABLE AND INCLUSIVE URBAN LIFESTYLE PRIOR...
STITCH: HOW MIGHT WE PROMOTE AN EQUITABLE AND INCLUSIVE URBAN LIFESTYLE PRIOR...STITCH: HOW MIGHT WE PROMOTE AN EQUITABLE AND INCLUSIVE URBAN LIFESTYLE PRIOR...
STITCH: HOW MIGHT WE PROMOTE AN EQUITABLE AND INCLUSIVE URBAN LIFESTYLE PRIOR...
 
guest bathroom white and blue ssssssssss
guest bathroom white and blue ssssssssssguest bathroom white and blue ssssssssss
guest bathroom white and blue ssssssssss
 
ALISIA: HOW MIGHT WE ACHIEVE HIGH ENVIRONMENTAL PERFORMANCE WHILE MAINTAINING...
ALISIA: HOW MIGHT WE ACHIEVE HIGH ENVIRONMENTAL PERFORMANCE WHILE MAINTAINING...ALISIA: HOW MIGHT WE ACHIEVE HIGH ENVIRONMENTAL PERFORMANCE WHILE MAINTAINING...
ALISIA: HOW MIGHT WE ACHIEVE HIGH ENVIRONMENTAL PERFORMANCE WHILE MAINTAINING...
 
TIMBRE: HOW MIGHT WE REMEDY MUSIC DESERTS AND FACILITATE GROWTH OF A MUSICAL ...
TIMBRE: HOW MIGHT WE REMEDY MUSIC DESERTS AND FACILITATE GROWTH OF A MUSICAL ...TIMBRE: HOW MIGHT WE REMEDY MUSIC DESERTS AND FACILITATE GROWTH OF A MUSICAL ...
TIMBRE: HOW MIGHT WE REMEDY MUSIC DESERTS AND FACILITATE GROWTH OF A MUSICAL ...
 
10 must-have Chrome extensions for designers
10 must-have Chrome extensions for designers10 must-have Chrome extensions for designers
10 must-have Chrome extensions for designers
 
Making and Unmaking of Chandigarh - A City of Two Plans2-4-24.ppt
Making and Unmaking of Chandigarh - A City of Two Plans2-4-24.pptMaking and Unmaking of Chandigarh - A City of Two Plans2-4-24.ppt
Making and Unmaking of Chandigarh - A City of Two Plans2-4-24.ppt
 
10 Best WordPress Plugins to make the website effective in 2024
10 Best WordPress Plugins to make the website effective in 202410 Best WordPress Plugins to make the website effective in 2024
10 Best WordPress Plugins to make the website effective in 2024
 
Interior Design for Office a cura di RMG Project Studio
Interior Design for Office a cura di RMG Project StudioInterior Design for Office a cura di RMG Project Studio
Interior Design for Office a cura di RMG Project Studio
 
FW25-26 Knit Cut & Sew Trend Book Peclers Paris
FW25-26 Knit Cut & Sew Trend Book Peclers ParisFW25-26 Knit Cut & Sew Trend Book Peclers Paris
FW25-26 Knit Cut & Sew Trend Book Peclers Paris
 
Niintendo Wii Presentation Template.pptx
Niintendo Wii Presentation Template.pptxNiintendo Wii Presentation Template.pptx
Niintendo Wii Presentation Template.pptx
 
Map of St. Louis Parks
Map of St. Louis Parks                              Map of St. Louis Parks
Map of St. Louis Parks
 
Imagist3D Architectural and Interior Rendering Portfolio
Imagist3D Architectural and Interior Rendering PortfolioImagist3D Architectural and Interior Rendering Portfolio
Imagist3D Architectural and Interior Rendering Portfolio
 

The Loop: An Introduction to WordPress Template Tags and Custom Queries

Notes de l'éditeur