SlideShare a Scribd company logo
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 (17)

PDF
Blogs and RSS – Trawling the Internet for Meaning
ESUG
 
PPTX
Blogging with drupal
Chris Ward
 
KEY
LeanStartup:Research is cheaper than development
John McCaffrey
 
ZIP
Unless It Was a Digital Dog, No One Ate Your Homework (Diigo)
Lisa Sjogren
 
PPTX
Graham Lavender on blogs and Twitter at John Abbott 2010
guybrariang
 
PPTX
Syndication in WordPress with RSS Scott Huntley
ePortfolios Australia
 
KEY
Becoming a more productive Rails Developer
John McCaffrey
 
PDF
The Non-Designer’s Guide to WordPress (Making Your Site Look Awesome)
Mykl Roventine
 
PDF
Accessible content
Maja Benke
 
PPTX
Blogging 101
Roselynn911
 
KEY
Social dev camp_2011
Craig Ulliott
 
KEY
Social media
Dale Cressman
 
PDF
The Non-designer's Guide to WordPress (Making Your Site Awesome)
Mykl Roventine
 
PPTX
How to Build Great Product – use blogging
Bhasker Vijaykumar Bhatt
 
PDF
Managing Multiple Authors with WordPress
Al Davis
 
KEY
Tumblrtail - Tumblr Developer's Meetup jp 2011
Naomoto Niwayama
 
Blogs and RSS – Trawling the Internet for Meaning
ESUG
 
Blogging with drupal
Chris Ward
 
LeanStartup:Research is cheaper than development
John McCaffrey
 
Unless It Was a Digital Dog, No One Ate Your Homework (Diigo)
Lisa Sjogren
 
Graham Lavender on blogs and Twitter at John Abbott 2010
guybrariang
 
Syndication in WordPress with RSS Scott Huntley
ePortfolios Australia
 
Becoming a more productive Rails Developer
John McCaffrey
 
The Non-Designer’s Guide to WordPress (Making Your Site Look Awesome)
Mykl Roventine
 
Accessible content
Maja Benke
 
Blogging 101
Roselynn911
 
Social dev camp_2011
Craig Ulliott
 
Social media
Dale Cressman
 
The Non-designer's Guide to WordPress (Making Your Site Awesome)
Mykl Roventine
 
How to Build Great Product – use blogging
Bhasker Vijaykumar Bhatt
 
Managing Multiple Authors with WordPress
Al Davis
 
Tumblrtail - Tumblr Developer's Meetup jp 2011
Naomoto Niwayama
 

Similar to Customizing the custom loop wordcamp 2012 (20)

PPTX
WordPress Themes 101 - PSUWeb13 Workshop
Curtiss Grymala
 
PPTX
Writing a WordPress Theme - HighEdWeb 2013 #WRK2
Curtiss Grymala
 
KEY
Gettingintotheloop 100123225021-phpapp01
Ravi Kumar
 
PDF
So, You Wanna Dev? Join the Team! - WordCamp Raleigh 2017
Evan Mullins
 
PPTX
WordPress Themes 101 - dotEduGuru Summit 2013
Curtiss Grymala
 
PPTX
WordPress Themes 101 - HighEdWeb New England 2013
Curtiss Grymala
 
PPSX
WordPress Theme Design and Development Workshop - Day 2
Mizanur Rahaman Mizan
 
PDF
WordPress A CMS for Beginners, Geeks and Those In-Between
Heidi Cool
 
PDF
Beginning WordPress Workshop
The Toolbox, Inc.
 
PPTX
The Way to Theme Enlightenment 2017
Amanda Giles
 
PDF
Intro to WordPress theme development
Thad Allender
 
PDF
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
Evan Mullins
 
PPTX
From WordPress With Love
Up2 Technology
 
PDF
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
Evan Mullins
 
PPTX
The Way to Theme Enlightenment
Amanda Giles
 
ZIP
WordPress as a CMS
Stephanie Leary
 
PDF
WordPress 101 Saturday Session
pamselle
 
PPTX
Theming Wordpress for Your Showcases
Jun Hu
 
PPTX
The WordPress University 2012
Stephanie Leary
 
PPTX
Saigon Wordpress Meetup - Themes Wordpress Meetup
Triết Sài Gòn
 
WordPress Themes 101 - PSUWeb13 Workshop
Curtiss Grymala
 
Writing a WordPress Theme - HighEdWeb 2013 #WRK2
Curtiss Grymala
 
Gettingintotheloop 100123225021-phpapp01
Ravi Kumar
 
So, You Wanna Dev? Join the Team! - WordCamp Raleigh 2017
Evan Mullins
 
WordPress Themes 101 - dotEduGuru Summit 2013
Curtiss Grymala
 
WordPress Themes 101 - HighEdWeb New England 2013
Curtiss Grymala
 
WordPress Theme Design and Development Workshop - Day 2
Mizanur Rahaman Mizan
 
WordPress A CMS for Beginners, Geeks and Those In-Between
Heidi Cool
 
Beginning WordPress Workshop
The Toolbox, Inc.
 
The Way to Theme Enlightenment 2017
Amanda Giles
 
Intro to WordPress theme development
Thad Allender
 
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
Evan Mullins
 
From WordPress With Love
Up2 Technology
 
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
Evan Mullins
 
The Way to Theme Enlightenment
Amanda Giles
 
WordPress as a CMS
Stephanie Leary
 
WordPress 101 Saturday Session
pamselle
 
Theming Wordpress for Your Showcases
Jun Hu
 
The WordPress University 2012
Stephanie Leary
 
Saigon Wordpress Meetup - Themes Wordpress Meetup
Triết Sài Gòn
 
Ad

Recently uploaded (20)

PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Python basic programing language for automation
DanialHabibi2
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Ad

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