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            WordPress for 7 years
   Years                   •  Worked a Gannet
•  Worked at Bloomberg        Newspapers
   Businessweek            •  Snappy Dresser
•  He's the one with the
   beard
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

query_posts() and get_posts() actually use this
 internally, but do other things that you don't 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/twentyten_jeff/standard-
  loop.php
Custom Loop Examples
 Homepage:
  https://github.com/jmarx/Wordcamp-NYC-
  2012/blob/master/twentyten_jeff/loop-index.php
 Sidebar:
  https://github.com/jmarx/Wordcamp-NYC-
  2012/blob/master/twentyten_jeff/sidebar.php
 Page
  https://github.com/jmarx/Wordcamp-NYC-
  2012/blob/master/twentyten_jeff/page_dc.php
Performance Gotchas
•   Use caching and transients to improve performance
•   Limits load by minimizing database calls
•   Don't need too many loops on your site
Got Questions?
@jeffreymarx
@asapountzis

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

More Related Content

What's hot

LeanStartup:Research is cheaper than development
LeanStartup:Research is cheaper than developmentLeanStartup:Research is cheaper than development
LeanStartup:Research is cheaper than development
John McCaffrey
 
Managing Multiple Authors with WordPress
Managing Multiple Authors with WordPressManaging Multiple Authors with WordPress
Managing Multiple Authors with WordPress
Al Davis
 
Tumblrtail - Tumblr Developer's Meetup jp 2011
Tumblrtail - Tumblr Developer's Meetup jp 2011Tumblrtail - Tumblr Developer's Meetup jp 2011
Tumblrtail - Tumblr Developer's Meetup jp 2011
Naomoto Niwayama
 

What's hot (18)

Blogs and RSS – Trawling the Internet for Meaning
Blogs and RSS – Trawling the Internet for MeaningBlogs and RSS – Trawling the Internet for Meaning
Blogs and RSS – Trawling the Internet for Meaning
 
Blogging with drupal
Blogging with drupalBlogging with drupal
Blogging with drupal
 
LeanStartup:Research is cheaper than development
LeanStartup:Research is cheaper than developmentLeanStartup:Research is cheaper than development
LeanStartup:Research is cheaper than development
 
Unless It Was a Digital Dog, No One Ate Your Homework (Diigo)
Unless It Was a Digital Dog, No One Ate Your Homework (Diigo)Unless It Was a Digital Dog, No One Ate Your Homework (Diigo)
Unless It Was a Digital Dog, No One Ate Your Homework (Diigo)
 
Graham Lavender on blogs and Twitter at John Abbott 2010
Graham Lavender on blogs and Twitter at John Abbott 2010Graham Lavender on blogs and Twitter at John Abbott 2010
Graham Lavender on blogs and Twitter at John Abbott 2010
 
Syndication in WordPress with RSS Scott Huntley
Syndication in WordPress with RSS  Scott HuntleySyndication in WordPress with RSS  Scott Huntley
Syndication in WordPress with RSS Scott Huntley
 
Becoming a more productive Rails Developer
Becoming a more productive Rails DeveloperBecoming a more productive Rails Developer
Becoming a more productive Rails Developer
 
The Non-Designer’s Guide to WordPress (Making Your Site Look Awesome)
The Non-Designer’s Guide to WordPress (Making Your Site Look Awesome)The Non-Designer’s Guide to WordPress (Making Your Site Look Awesome)
The Non-Designer’s Guide to WordPress (Making Your Site Look Awesome)
 
Accessible content
Accessible contentAccessible content
Accessible content
 
Blogging 101
Blogging 101Blogging 101
Blogging 101
 
Social dev camp_2011
Social dev camp_2011Social dev camp_2011
Social dev camp_2011
 
Social media
Social mediaSocial media
Social media
 
The Non-designer's Guide to WordPress (Making Your Site Awesome)
The Non-designer's Guide to WordPress (Making Your Site Awesome)The Non-designer's Guide to WordPress (Making Your Site Awesome)
The Non-designer's Guide to WordPress (Making Your Site Awesome)
 
How to Build Great Product – use blogging
How to Build Great Product – use bloggingHow to Build Great Product – use blogging
How to Build Great Product – use blogging
 
Adobe Education Blog: Get Writing!
Adobe Education Blog: Get Writing!Adobe Education Blog: Get Writing!
Adobe Education Blog: Get Writing!
 
Managing Multiple Authors with WordPress
Managing Multiple Authors with WordPressManaging Multiple Authors with WordPress
Managing Multiple Authors with WordPress
 
Blogging pains
Blogging painsBlogging pains
Blogging pains
 
Tumblrtail - Tumblr Developer's Meetup jp 2011
Tumblrtail - Tumblr Developer's Meetup jp 2011Tumblrtail - Tumblr Developer's Meetup jp 2011
Tumblrtail - Tumblr Developer's Meetup jp 2011
 

Similar to Customizing the custom loop wordcamp 2012

PEPY Wordpress workshop-01
PEPY Wordpress workshop-01PEPY Wordpress workshop-01
PEPY Wordpress workshop-01
Wei Peng
 
Yahoo! Search monkey API - CEBIT 2008
Yahoo! Search monkey API - CEBIT 2008Yahoo! Search monkey API - CEBIT 2008
Yahoo! Search monkey API - CEBIT 2008
Eric D.
 
Theming moodle technical
Theming moodle   technicalTheming moodle   technical
Theming moodle technical
Alex Walker
 
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
Josh Guffey
 
Austin NoSQL 2011-07-06
Austin NoSQL 2011-07-06Austin NoSQL 2011-07-06
Austin NoSQL 2011-07-06
jimbojsb
 

Similar to Customizing the custom loop wordcamp 2012 (20)

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
 
PEPY Wordpress workshop-01
PEPY Wordpress workshop-01PEPY Wordpress workshop-01
PEPY Wordpress workshop-01
 
6 reasons Jubilee could be a Rubyist's new best friend
6 reasons Jubilee could be a Rubyist's new best friend6 reasons Jubilee could be a Rubyist's new best friend
6 reasons Jubilee could be a Rubyist's new best friend
 
Yahoo! Search monkey API - CEBIT 2008
Yahoo! Search monkey API - CEBIT 2008Yahoo! Search monkey API - CEBIT 2008
Yahoo! Search monkey API - CEBIT 2008
 
Theming moodle technical
Theming moodle   technicalTheming moodle   technical
Theming moodle technical
 
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
 
"Problems and solutions with generative and non-generative AI models deployme...
"Problems and solutions with generative and non-generative AI models deployme..."Problems and solutions with generative and non-generative AI models deployme...
"Problems and solutions with generative and non-generative AI models deployme...
 
Working with WordPress themes
Working with WordPress themesWorking with WordPress themes
Working with WordPress themes
 
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)
 
A tale of 3 databases
A tale of 3 databasesA tale of 3 databases
A tale of 3 databases
 
Keeping MongoDB Data Safe
Keeping MongoDB Data SafeKeeping MongoDB Data Safe
Keeping MongoDB Data Safe
 
Austin NoSQL 2011-07-06
Austin NoSQL 2011-07-06Austin NoSQL 2011-07-06
Austin NoSQL 2011-07-06
 
onGameStart
onGameStartonGameStart
onGameStart
 
WebGL Camp 4 - A3 3D Engine
WebGL Camp 4 - A3 3D EngineWebGL Camp 4 - A3 3D Engine
WebGL Camp 4 - A3 3D Engine
 
WordPress Themes Demystified
WordPress Themes DemystifiedWordPress Themes Demystified
WordPress Themes Demystified
 
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
 
Design todevelop
Design todevelopDesign todevelop
Design todevelop
 
Forget The ORM!
Forget The ORM!Forget The ORM!
Forget The ORM!
 
Why I will never write JavaScript ever again*
Why I will never write JavaScript ever again*Why I will never write JavaScript ever again*
Why I will never write JavaScript ever again*
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 

Customizing the custom loop wordcamp 2012

  • 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 WordPress for 7 years Years • Worked a Gannet • Worked at Bloomberg Newspapers Businessweek • Snappy Dresser • He's the one with the beard
  • 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 query_posts() and get_posts() actually use this internally, but do other things that you don't 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/twentyten_jeff/standard- loop.php
  • 15. Custom Loop Examples  Homepage: https://github.com/jmarx/Wordcamp-NYC- 2012/blob/master/twentyten_jeff/loop-index.php  Sidebar: https://github.com/jmarx/Wordcamp-NYC- 2012/blob/master/twentyten_jeff/sidebar.php  Page https://github.com/jmarx/Wordcamp-NYC- 2012/blob/master/twentyten_jeff/page_dc.php
  • 16. Performance Gotchas • Use caching and transients to improve performance • Limits load by minimizing database calls • Don't need too many loops on your site