SlideShare a Scribd company logo
1 of 17
Welcome

              Customizing the Custom Loop




Code: http://github.com/jmarx/Wordcamp-NYC-2012
Meet the guys

Alexander Sapountzis     Jeff Marx
•Worked with             • Worked with
 WordPress for 2 Years     WordPress for 7 years
•Worked at Bloomberg     • Worked at Gannett
 Businessweek              Newspapers
•He's the one with the   • Not the guy from the
 beard                     Sopranos (even though
                           he looks like him)
What is CBS Local?

 Network of local sites for news and media,
  consolidating CBS' media content
 •Radio
 •TV
 •News
 •Original Content

 www.cbslocal.com
We use WordPress!
After the five-minute install

                          •
                          •
                               You get a cool theme


                          •
                               Single Column


                          •
                               Sidebar
                               ...but it's boring



                          We need to customize this so it's
                              cool!
What comes next?

•   Featured Posts
•   Category Boxes
•   Cool stuff
•   Not boring!
How do we do this?

 (pay attention, this will be on the test)
The Global Query

•   Runs once on every page
•   Returns all relevant posts based on params
    o Home Page Query returns all posts
    o Category Page Query returns all for that category
    o Single Post Page Query returns a single, lonely post

•   Global query feeds default loop
    o   default loop is hard coded on theme template files and
        contains post information from the global query
•   This comes built into WordPress
WordPress does all this for free

...what's the problem? Why bother with custom
   loops?

Because you may need to:
•Categorize content
•use Custom Post Types
•not have a boring site
Introduce The Loops

•   query_posts()
•   WP_Query
•   get_posts()

Each is used in different ways, but you really only
  need one: WP_Query
query_posts()

•   Modifies the Global Query (that's bad)
•   Can cause unpredictable behavior
•   Will very likely be removed from WordPress (we
    hope soon)
•   Ignore tutorials that use this

Remember: using query_posts() is like trying to
  hammer a nail in with your forehead; painful and
  messy
get_posts()

•   Safer but not ideal
•   Limited - Not as powerful or useful
•   Some template tags are not included

This is like the little brother of WP_Query. It uses
  WP_Query behind the scenes, but hides quite a
  bit from you
WP_Query

•    Returns everything you need
•    Template tags will work
•    Plays nice with the Global Query
•    High in fiber
    http://codex.wordpress.org/Class_Reference/WP_Query


     query_posts() and get_posts() actually use this
     internally, but either do other things that you
     don't want or won’t give you what you want.
    Cut out the middle man!
Standard Loop

Examples of the standard loop (before we make it all
 fancy)

https://
  github.com/jmarx/Wordcamp-NYC-2012/blob/master
Custom Loop Examples

 Homepage:
  https://
  github.com/jmarx/Wordcamp-NYC-2012/blob/master/twenty
 Sidebar:
  https://
  github.com/jmarx/Wordcamp-NYC-2012/blob/master/twenty
 Page
  https://
  github.com/jmarx/Wordcamp-NYC-2012/blob/master/twenty
Performance Gotchas

•   Use caching and transients to improve performance
•   Limits load by minimizing database calls
•   Always cache your site when using custom loops!



Links:
http://wordpress.org/extend/plugins/wp-super-cache/
http://wordpress.org/extend/plugins/w3-total-cache/
http://codex.wordpress.org/Transients_API
Got Questions?

@jeffreymarx
@asapountzis

Code Samples/Resources:
https://github.com/jmarx/Wordcamp-NYC-2012

More Related Content

What's hot

Thing to love in Clojure
Thing to love in ClojureThing to love in Clojure
Thing to love in ClojureJiří Knesl
 
WordPress Media in a post-Koop Universe
WordPress Media in a post-Koop UniverseWordPress Media in a post-Koop Universe
WordPress Media in a post-Koop UniverseScott Taylor
 
This is presentation at Mitaka.rb #10.
This is presentation at Mitaka.rb #10.This is presentation at Mitaka.rb #10.
This is presentation at Mitaka.rb #10.Masaki Komagata
 
Startup Weekend & LocomotiveCMS (In Chinese)
Startup Weekend & LocomotiveCMS (In Chinese)Startup Weekend & LocomotiveCMS (In Chinese)
Startup Weekend & LocomotiveCMS (In Chinese)Zac Zheng
 
LeanStartup:Research is cheaper than development
LeanStartup:Research is cheaper than developmentLeanStartup:Research is cheaper than development
LeanStartup:Research is cheaper than developmentJohn McCaffrey
 
Getting started with dev tools (4/10/17 DC)
Getting started with dev tools (4/10/17 DC)Getting started with dev tools (4/10/17 DC)
Getting started with dev tools (4/10/17 DC)Daniel Friedman
 
Custom Post Types in the wild (WordCamp Sofia 2012)
Custom Post Types in the wild (WordCamp Sofia 2012)Custom Post Types in the wild (WordCamp Sofia 2012)
Custom Post Types in the wild (WordCamp Sofia 2012)Mario Peshev
 
Convert a Site Template to a Drupal 7 Theme using SASS or LESS and Zurb Found...
Convert a Site Template to a Drupal 7 Theme using SASS or LESS and Zurb Found...Convert a Site Template to a Drupal 7 Theme using SASS or LESS and Zurb Found...
Convert a Site Template to a Drupal 7 Theme using SASS or LESS and Zurb Found...Carlos Ospina
 
NoTube User Model slides
NoTube User Model slidesNoTube User Model slides
NoTube User Model slidesDan Brickley
 
How to create a podcast
How to create a podcastHow to create a podcast
How to create a podcastChip Dizárd
 
Carrington Core (2014)
Carrington Core (2014)Carrington Core (2014)
Carrington Core (2014)alexkingorg
 
WebGL Camp 4 - A3 3D Engine
WebGL Camp 4 - A3 3D EngineWebGL Camp 4 - A3 3D Engine
WebGL Camp 4 - A3 3D Engineaerotwist
 
Custom post types - WordPress
Custom post types - WordPressCustom post types - WordPress
Custom post types - WordPresskeithdevon
 
Site Builders: Let's clean up our UIs!
Site Builders: Let's clean up our UIs!Site Builders: Let's clean up our UIs!
Site Builders: Let's clean up our UIs!cherryhillco
 
Advanced Custom Fields Lightning Talk WordCamp Miami 2018
Advanced Custom Fields Lightning Talk WordCamp Miami 2018Advanced Custom Fields Lightning Talk WordCamp Miami 2018
Advanced Custom Fields Lightning Talk WordCamp Miami 2018Jesse Velez
 

What's hot (20)

Thing to love in Clojure
Thing to love in ClojureThing to love in Clojure
Thing to love in Clojure
 
WordPress Media in a post-Koop Universe
WordPress Media in a post-Koop UniverseWordPress Media in a post-Koop Universe
WordPress Media in a post-Koop Universe
 
Down and Dirty EPUB 3
Down and Dirty EPUB 3Down and Dirty EPUB 3
Down and Dirty EPUB 3
 
This is presentation at Mitaka.rb #10.
This is presentation at Mitaka.rb #10.This is presentation at Mitaka.rb #10.
This is presentation at Mitaka.rb #10.
 
Startup Weekend & LocomotiveCMS (In Chinese)
Startup Weekend & LocomotiveCMS (In Chinese)Startup Weekend & LocomotiveCMS (In Chinese)
Startup Weekend & LocomotiveCMS (In Chinese)
 
LeanStartup:Research is cheaper than development
LeanStartup:Research is cheaper than developmentLeanStartup:Research is cheaper than development
LeanStartup:Research is cheaper than development
 
Getting started with dev tools (4/10/17 DC)
Getting started with dev tools (4/10/17 DC)Getting started with dev tools (4/10/17 DC)
Getting started with dev tools (4/10/17 DC)
 
Custom Post Types in the wild (WordCamp Sofia 2012)
Custom Post Types in the wild (WordCamp Sofia 2012)Custom Post Types in the wild (WordCamp Sofia 2012)
Custom Post Types in the wild (WordCamp Sofia 2012)
 
Convert a Site Template to a Drupal 7 Theme using SASS or LESS and Zurb Found...
Convert a Site Template to a Drupal 7 Theme using SASS or LESS and Zurb Found...Convert a Site Template to a Drupal 7 Theme using SASS or LESS and Zurb Found...
Convert a Site Template to a Drupal 7 Theme using SASS or LESS and Zurb Found...
 
Design todevelop
Design todevelopDesign todevelop
Design todevelop
 
Ansible for Automation
Ansible for AutomationAnsible for Automation
Ansible for Automation
 
NoTube User Model slides
NoTube User Model slidesNoTube User Model slides
NoTube User Model slides
 
Blogging
BloggingBlogging
Blogging
 
How to create a podcast
How to create a podcastHow to create a podcast
How to create a podcast
 
Carrington Core (2014)
Carrington Core (2014)Carrington Core (2014)
Carrington Core (2014)
 
WebGL Camp 4 - A3 3D Engine
WebGL Camp 4 - A3 3D EngineWebGL Camp 4 - A3 3D Engine
WebGL Camp 4 - A3 3D Engine
 
Intro to EmberJS
Intro to EmberJSIntro to EmberJS
Intro to EmberJS
 
Custom post types - WordPress
Custom post types - WordPressCustom post types - WordPress
Custom post types - WordPress
 
Site Builders: Let's clean up our UIs!
Site Builders: Let's clean up our UIs!Site Builders: Let's clean up our UIs!
Site Builders: Let's clean up our UIs!
 
Advanced Custom Fields Lightning Talk WordCamp Miami 2018
Advanced Custom Fields Lightning Talk WordCamp Miami 2018Advanced Custom Fields Lightning Talk WordCamp Miami 2018
Advanced Custom Fields Lightning Talk WordCamp Miami 2018
 

Similar to Customizing the custom loop wordcamp 2012-jeff

Customizing the custom loop wordcamp 2012
Customizing the custom loop   wordcamp 2012Customizing the custom loop   wordcamp 2012
Customizing the custom loop wordcamp 2012Alexander Sapountzis
 
Building a Simple Theme Framework
Building a Simple Theme FrameworkBuilding a Simple Theme Framework
Building a Simple Theme FrameworkJoe Casabona
 
Rails development environment talk
Rails development environment talkRails development environment talk
Rails development environment talkReuven Lerner
 
WordPress Themes Demystified
WordPress Themes DemystifiedWordPress Themes Demystified
WordPress Themes DemystifiedChris Burgess
 
Open Standards in the Walled Garden
Open Standards in the Walled GardenOpen Standards in the Walled Garden
Open Standards in the Walled Gardendigitalbindery
 
How to Choose a WordPress Theme
How to Choose a WordPress ThemeHow to Choose a WordPress Theme
How to Choose a WordPress ThemeNew Tricks
 
Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)Mike Schinkel
 
Taking WordPress as a CMS, to the Limit
Taking WordPress as a CMS, to the LimitTaking WordPress as a CMS, to the Limit
Taking WordPress as a CMS, to the LimitJosh Guffey
 
Yahoo! Search monkey API - CEBIT 2008
Yahoo! Search monkey API - CEBIT 2008Yahoo! Search monkey API - CEBIT 2008
Yahoo! Search monkey API - CEBIT 2008Eric D.
 
PEPY Wordpress workshop-01
PEPY Wordpress workshop-01PEPY Wordpress workshop-01
PEPY Wordpress workshop-01Wei Peng
 
Writing a WordPress Theme - HighEdWeb 2013 #WRK2
Writing a WordPress Theme - HighEdWeb 2013 #WRK2Writing a WordPress Theme - HighEdWeb 2013 #WRK2
Writing a WordPress Theme - HighEdWeb 2013 #WRK2Curtiss Grymala
 
MongoDB and Ecommerce : A perfect combination
MongoDB and Ecommerce : A perfect combinationMongoDB and Ecommerce : A perfect combination
MongoDB and Ecommerce : A perfect combinationSteven Francia
 
Gettingintotheloop 100123225021-phpapp01
Gettingintotheloop 100123225021-phpapp01Gettingintotheloop 100123225021-phpapp01
Gettingintotheloop 100123225021-phpapp01Ravi Kumar
 
Austin NoSQL 2011-07-06
Austin NoSQL 2011-07-06Austin NoSQL 2011-07-06
Austin NoSQL 2011-07-06jimbojsb
 
Theming moodle technical
Theming moodle   technicalTheming moodle   technical
Theming moodle technicalAlex Walker
 
Child Theme Frameworks
Child Theme FrameworksChild Theme Frameworks
Child Theme Frameworksryngrn
 
Responsive themeworkshop wcneo2016
Responsive themeworkshop wcneo2016Responsive themeworkshop wcneo2016
Responsive themeworkshop wcneo2016David Brattoli
 

Similar to Customizing the custom loop wordcamp 2012-jeff (20)

Customizing the custom loop wordcamp 2012
Customizing the custom loop   wordcamp 2012Customizing the custom loop   wordcamp 2012
Customizing the custom loop wordcamp 2012
 
Building a Simple Theme Framework
Building a Simple Theme FrameworkBuilding a Simple Theme Framework
Building a Simple Theme Framework
 
Rails development environment talk
Rails development environment talkRails development environment talk
Rails development environment talk
 
onGameStart
onGameStartonGameStart
onGameStart
 
WordPress Themes Demystified
WordPress Themes DemystifiedWordPress Themes Demystified
WordPress Themes Demystified
 
Open Standards in the Walled Garden
Open Standards in the Walled GardenOpen Standards in the Walled Garden
Open Standards in the Walled Garden
 
How to Choose a WordPress Theme
How to Choose a WordPress ThemeHow to Choose a WordPress Theme
How to Choose a WordPress Theme
 
Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)
 
Taking WordPress as a CMS, to the Limit
Taking WordPress as a CMS, to the LimitTaking WordPress as a CMS, to the Limit
Taking WordPress as a CMS, to the Limit
 
Yahoo! Search monkey API - CEBIT 2008
Yahoo! Search monkey API - CEBIT 2008Yahoo! Search monkey API - CEBIT 2008
Yahoo! Search monkey API - CEBIT 2008
 
PEPY Wordpress workshop-01
PEPY Wordpress workshop-01PEPY Wordpress workshop-01
PEPY Wordpress workshop-01
 
Writing a WordPress Theme - HighEdWeb 2013 #WRK2
Writing a WordPress Theme - HighEdWeb 2013 #WRK2Writing a WordPress Theme - HighEdWeb 2013 #WRK2
Writing a WordPress Theme - HighEdWeb 2013 #WRK2
 
MongoDB and Ecommerce : A perfect combination
MongoDB and Ecommerce : A perfect combinationMongoDB and Ecommerce : A perfect combination
MongoDB and Ecommerce : A perfect combination
 
Gettingintotheloop 100123225021-phpapp01
Gettingintotheloop 100123225021-phpapp01Gettingintotheloop 100123225021-phpapp01
Gettingintotheloop 100123225021-phpapp01
 
Austin NoSQL 2011-07-06
Austin NoSQL 2011-07-06Austin NoSQL 2011-07-06
Austin NoSQL 2011-07-06
 
Theming moodle technical
Theming moodle   technicalTheming moodle   technical
Theming moodle technical
 
Working with WordPress themes
Working with WordPress themesWorking with WordPress themes
Working with WordPress themes
 
OOP in JS
OOP in JSOOP in JS
OOP in JS
 
Child Theme Frameworks
Child Theme FrameworksChild Theme Frameworks
Child Theme Frameworks
 
Responsive themeworkshop wcneo2016
Responsive themeworkshop wcneo2016Responsive themeworkshop wcneo2016
Responsive themeworkshop wcneo2016
 

Recently uploaded

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 

Recently uploaded (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 

Customizing the custom loop wordcamp 2012-jeff

  • 1. Welcome Customizing the Custom Loop Code: http://github.com/jmarx/Wordcamp-NYC-2012
  • 2. Meet the guys Alexander Sapountzis Jeff Marx •Worked with • Worked with WordPress for 2 Years WordPress for 7 years •Worked at Bloomberg • Worked at Gannett Businessweek Newspapers •He's the one with the • Not the guy from the beard Sopranos (even though he looks like him)
  • 3. What is CBS Local? Network of local sites for news and media, consolidating CBS' media content •Radio •TV •News •Original Content www.cbslocal.com
  • 5. After the five-minute install • • You get a cool theme • Single Column • Sidebar ...but it's boring We need to customize this so it's cool!
  • 6. What comes next? • Featured Posts • Category Boxes • Cool stuff • Not boring!
  • 7. How do we do this? (pay attention, this will be on the test)
  • 8. The Global Query • Runs once on every page • Returns all relevant posts based on params o Home Page Query returns all posts o Category Page Query returns all for that category o Single Post Page Query returns a single, lonely post • Global query feeds default loop o default loop is hard coded on theme template files and contains post information from the global query • This comes built into WordPress
  • 9. WordPress does all this for free ...what's the problem? Why bother with custom loops? Because you may need to: •Categorize content •use Custom Post Types •not have a boring site
  • 10. Introduce The Loops • query_posts() • WP_Query • get_posts() Each is used in different ways, but you really only need one: WP_Query
  • 11. query_posts() • Modifies the Global Query (that's bad) • Can cause unpredictable behavior • Will very likely be removed from WordPress (we hope soon) • Ignore tutorials that use this Remember: using query_posts() is like trying to hammer a nail in with your forehead; painful and messy
  • 12. get_posts() • Safer but not ideal • Limited - Not as powerful or useful • Some template tags are not included This is like the little brother of WP_Query. It uses WP_Query behind the scenes, but hides quite a bit from you
  • 13. WP_Query • Returns everything you need • Template tags will work • Plays nice with the Global Query • High in fiber  http://codex.wordpress.org/Class_Reference/WP_Query query_posts() and get_posts() actually use this internally, but either do other things that you don't want or won’t give you what you want. Cut out the middle man!
  • 14. Standard Loop Examples of the standard loop (before we make it all fancy) https:// github.com/jmarx/Wordcamp-NYC-2012/blob/master
  • 15. Custom Loop Examples  Homepage: https:// github.com/jmarx/Wordcamp-NYC-2012/blob/master/twenty  Sidebar: https:// github.com/jmarx/Wordcamp-NYC-2012/blob/master/twenty  Page https:// github.com/jmarx/Wordcamp-NYC-2012/blob/master/twenty
  • 16. Performance Gotchas • Use caching and transients to improve performance • Limits load by minimizing database calls • Always cache your site when using custom loops! Links: http://wordpress.org/extend/plugins/wp-super-cache/ http://wordpress.org/extend/plugins/w3-total-cache/ http://codex.wordpress.org/Transients_API