SlideShare uma empresa Scribd logo
1 de 15
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

Mais conteúdo relacionado

Semelhante a 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 Mistake From Blogger
SEO Mistake From BloggerSEO Mistake From Blogger
SEO Mistake From BloggerSeo Indonesia
 
SEO Method For Blogger
SEO Method For BloggerSEO Method For Blogger
SEO Method For 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
 

Semelhante a 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 Mistake From Blogger
SEO Mistake From BloggerSEO Mistake From Blogger
SEO Mistake From Blogger
 
SEO Mistakes
SEO MistakesSEO Mistakes
SEO Mistakes
 
SEO Method For Blogger
SEO Method For BloggerSEO Method For Blogger
SEO Method For 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
 

Mais 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
 

Mais 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
 

Último

Design principles on typography in design
Design principles on typography in designDesign principles on typography in design
Design principles on typography in designnooreen17
 
PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024
PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024
PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024CristobalHeraud
 
办理(USYD毕业证书)澳洲悉尼大学毕业证成绩单原版一比一
办理(USYD毕业证书)澳洲悉尼大学毕业证成绩单原版一比一办理(USYD毕业证书)澳洲悉尼大学毕业证成绩单原版一比一
办理(USYD毕业证书)澳洲悉尼大学毕业证成绩单原版一比一diploma 1
 
Untitled presedddddddddddddddddntation (1).pptx
Untitled presedddddddddddddddddntation (1).pptxUntitled presedddddddddddddddddntation (1).pptx
Untitled presedddddddddddddddddntation (1).pptxmapanig881
 
Call Us ✡️97111⇛47426⇛Call In girls Vasant Vihar༒(Delhi)
Call Us ✡️97111⇛47426⇛Call In girls Vasant Vihar༒(Delhi)Call Us ✡️97111⇛47426⇛Call In girls Vasant Vihar༒(Delhi)
Call Us ✡️97111⇛47426⇛Call In girls Vasant Vihar༒(Delhi)jennyeacort
 
Passbook project document_april_21__.pdf
Passbook project document_april_21__.pdfPassbook project document_april_21__.pdf
Passbook project document_april_21__.pdfvaibhavkanaujia
 
Top 10 Modern Web Design Trends for 2025
Top 10 Modern Web Design Trends for 2025Top 10 Modern Web Design Trends for 2025
Top 10 Modern Web Design Trends for 2025Rndexperts
 
306MTAMount UCLA University Bachelor's Diploma in Social Media
306MTAMount UCLA University Bachelor's Diploma in Social Media306MTAMount UCLA University Bachelor's Diploma in Social Media
306MTAMount UCLA University Bachelor's Diploma in Social MediaD SSS
 
2024新版美国旧金山州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
2024新版美国旧金山州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree2024新版美国旧金山州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
2024新版美国旧金山州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degreeyuu sss
 
昆士兰大学毕业证(UQ毕业证)#文凭成绩单#真实留信学历认证永久存档
昆士兰大学毕业证(UQ毕业证)#文凭成绩单#真实留信学历认证永久存档昆士兰大学毕业证(UQ毕业证)#文凭成绩单#真实留信学历认证永久存档
昆士兰大学毕业证(UQ毕业证)#文凭成绩单#真实留信学历认证永久存档208367051
 
How to Empower the future of UX Design with Gen AI
How to Empower the future of UX Design with Gen AIHow to Empower the future of UX Design with Gen AI
How to Empower the future of UX Design with Gen AIyuj
 
cda.pptx critical discourse analysis ppt
cda.pptx critical discourse analysis pptcda.pptx critical discourse analysis ppt
cda.pptx critical discourse analysis pptMaryamAfzal41
 
Mookuthi is an artisanal nose ornament brand based in Madras.
Mookuthi is an artisanal nose ornament brand based in Madras.Mookuthi is an artisanal nose ornament brand based in Madras.
Mookuthi is an artisanal nose ornament brand based in Madras.Mookuthi
 
原版1:1定制堪培拉大学毕业证(UC毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制堪培拉大学毕业证(UC毕业证)#文凭成绩单#真实留信学历认证永久存档原版1:1定制堪培拉大学毕业证(UC毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制堪培拉大学毕业证(UC毕业证)#文凭成绩单#真实留信学历认证永久存档208367051
 
Unveiling the Future: Columbus, Ohio Condominiums Through the Lens of 3D Arch...
Unveiling the Future: Columbus, Ohio Condominiums Through the Lens of 3D Arch...Unveiling the Future: Columbus, Ohio Condominiums Through the Lens of 3D Arch...
Unveiling the Future: Columbus, Ohio Condominiums Through the Lens of 3D Arch...Yantram Animation Studio Corporation
 
Pharmaceutical Packaging for the elderly.pdf
Pharmaceutical Packaging for the elderly.pdfPharmaceutical Packaging for the elderly.pdf
Pharmaceutical Packaging for the elderly.pdfAayushChavan5
 
办理学位证(NTU证书)新加坡南洋理工大学毕业证成绩单原版一比一
办理学位证(NTU证书)新加坡南洋理工大学毕业证成绩单原版一比一办理学位证(NTU证书)新加坡南洋理工大学毕业证成绩单原版一比一
办理学位证(NTU证书)新加坡南洋理工大学毕业证成绩单原版一比一A SSS
 
MT. Marseille an Archipelago. Strategies for Integrating Residential Communit...
MT. Marseille an Archipelago. Strategies for Integrating Residential Communit...MT. Marseille an Archipelago. Strategies for Integrating Residential Communit...
MT. Marseille an Archipelago. Strategies for Integrating Residential Communit...katerynaivanenko1
 
PORTAFOLIO 2024_ ANASTASIYA KUDINOVA
PORTAFOLIO   2024_  ANASTASIYA  KUDINOVAPORTAFOLIO   2024_  ANASTASIYA  KUDINOVA
PORTAFOLIO 2024_ ANASTASIYA KUDINOVAAnastasiya Kudinova
 
办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一
办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一
办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一F La
 

Último (20)

Design principles on typography in design
Design principles on typography in designDesign principles on typography in design
Design principles on typography in design
 
PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024
PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024
PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024
 
办理(USYD毕业证书)澳洲悉尼大学毕业证成绩单原版一比一
办理(USYD毕业证书)澳洲悉尼大学毕业证成绩单原版一比一办理(USYD毕业证书)澳洲悉尼大学毕业证成绩单原版一比一
办理(USYD毕业证书)澳洲悉尼大学毕业证成绩单原版一比一
 
Untitled presedddddddddddddddddntation (1).pptx
Untitled presedddddddddddddddddntation (1).pptxUntitled presedddddddddddddddddntation (1).pptx
Untitled presedddddddddddddddddntation (1).pptx
 
Call Us ✡️97111⇛47426⇛Call In girls Vasant Vihar༒(Delhi)
Call Us ✡️97111⇛47426⇛Call In girls Vasant Vihar༒(Delhi)Call Us ✡️97111⇛47426⇛Call In girls Vasant Vihar༒(Delhi)
Call Us ✡️97111⇛47426⇛Call In girls Vasant Vihar༒(Delhi)
 
Passbook project document_april_21__.pdf
Passbook project document_april_21__.pdfPassbook project document_april_21__.pdf
Passbook project document_april_21__.pdf
 
Top 10 Modern Web Design Trends for 2025
Top 10 Modern Web Design Trends for 2025Top 10 Modern Web Design Trends for 2025
Top 10 Modern Web Design Trends for 2025
 
306MTAMount UCLA University Bachelor's Diploma in Social Media
306MTAMount UCLA University Bachelor's Diploma in Social Media306MTAMount UCLA University Bachelor's Diploma in Social Media
306MTAMount UCLA University Bachelor's Diploma in Social Media
 
2024新版美国旧金山州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
2024新版美国旧金山州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree2024新版美国旧金山州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
2024新版美国旧金山州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
 
昆士兰大学毕业证(UQ毕业证)#文凭成绩单#真实留信学历认证永久存档
昆士兰大学毕业证(UQ毕业证)#文凭成绩单#真实留信学历认证永久存档昆士兰大学毕业证(UQ毕业证)#文凭成绩单#真实留信学历认证永久存档
昆士兰大学毕业证(UQ毕业证)#文凭成绩单#真实留信学历认证永久存档
 
How to Empower the future of UX Design with Gen AI
How to Empower the future of UX Design with Gen AIHow to Empower the future of UX Design with Gen AI
How to Empower the future of UX Design with Gen AI
 
cda.pptx critical discourse analysis ppt
cda.pptx critical discourse analysis pptcda.pptx critical discourse analysis ppt
cda.pptx critical discourse analysis ppt
 
Mookuthi is an artisanal nose ornament brand based in Madras.
Mookuthi is an artisanal nose ornament brand based in Madras.Mookuthi is an artisanal nose ornament brand based in Madras.
Mookuthi is an artisanal nose ornament brand based in Madras.
 
原版1:1定制堪培拉大学毕业证(UC毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制堪培拉大学毕业证(UC毕业证)#文凭成绩单#真实留信学历认证永久存档原版1:1定制堪培拉大学毕业证(UC毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制堪培拉大学毕业证(UC毕业证)#文凭成绩单#真实留信学历认证永久存档
 
Unveiling the Future: Columbus, Ohio Condominiums Through the Lens of 3D Arch...
Unveiling the Future: Columbus, Ohio Condominiums Through the Lens of 3D Arch...Unveiling the Future: Columbus, Ohio Condominiums Through the Lens of 3D Arch...
Unveiling the Future: Columbus, Ohio Condominiums Through the Lens of 3D Arch...
 
Pharmaceutical Packaging for the elderly.pdf
Pharmaceutical Packaging for the elderly.pdfPharmaceutical Packaging for the elderly.pdf
Pharmaceutical Packaging for the elderly.pdf
 
办理学位证(NTU证书)新加坡南洋理工大学毕业证成绩单原版一比一
办理学位证(NTU证书)新加坡南洋理工大学毕业证成绩单原版一比一办理学位证(NTU证书)新加坡南洋理工大学毕业证成绩单原版一比一
办理学位证(NTU证书)新加坡南洋理工大学毕业证成绩单原版一比一
 
MT. Marseille an Archipelago. Strategies for Integrating Residential Communit...
MT. Marseille an Archipelago. Strategies for Integrating Residential Communit...MT. Marseille an Archipelago. Strategies for Integrating Residential Communit...
MT. Marseille an Archipelago. Strategies for Integrating Residential Communit...
 
PORTAFOLIO 2024_ ANASTASIYA KUDINOVA
PORTAFOLIO   2024_  ANASTASIYA  KUDINOVAPORTAFOLIO   2024_  ANASTASIYA  KUDINOVA
PORTAFOLIO 2024_ ANASTASIYA KUDINOVA
 
办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一
办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一
办理(宾州州立毕业证书)美国宾夕法尼亚州立大学毕业证成绩单原版一比一
 

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

Notas do Editor