SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Parsing Strange:URL to SQL to HTML Hal Stern http://snowmanonfire.com headshot by Richard Stevenshttp://dieselsweeties.com
Why Do You Care? Database performance = user experience A little database expertise goes a long way Use taxonomies for more than sidebar lists WordPress is a powerful CMS Change default behaviors Defy the common wisdom Integrate other content sources/filters WordCamp Chicago 2
Disclaimers I’m somewhat social, for Jersey I’m (old) old school If using PHP echo gives you hives……take a Benadryl now If “INNER JOIN” makes you giggle, you’re in the wrong session/conference/fantasy I suck at art and design 3 WordCamp Chicago
Flow of Control Web server URL manipulation Real file or permalink URL? URL to query variables What to display? Tag? Post? Category? Query variables to SQL generation How exactly to get that content? Template file selection How will content be displayed? Content manipulation 4 WordCamp Chicago
Whose File Is This? User URL request passed to web server Web server checks.htaccessfile WP install root  Other .htaccessfiles may interfere Basic rewriting rules:If file or directory URL doesn’t exist, start WordPress via index.php WordCamp Chicago 5 <IfModulemod_rewrite.c> RewriteEngine On RewriteBase /whereyouputWordPress/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
What Happens Before The Loop Parse URL into a query Set conditionals & select templates Execute the query & cache results Run the Loop:<?phpif (have_posts()) : 	   while (have_posts()) : the_post();    //loop contentendwhile;endif;?> WordCamp Chicago 6
Examining the Query String SQL passed to MySQL in WP_Query object’s request element Brute force: edit theme footer.phpto see main loop’s query for displayed page WordCamp Chicago 7 <?php   global $wp_query;   echo ”SQL for this page ";   echo $wp_query->request;   echo "<br>"; ?>
SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post’ AND(wp_posts.post_status = 'publish' ORwp_posts.post_status = 'private’)ORDER BY wp_posts.post_date DESC LIMIT 0, 10 “Home Page” Query Deconstruction WordCamp Chicago 8 Get all fields from posts table, but limit number of returned rows Only get posts, and those that are published or private to the user Sort the results by date in descending order Start results starting with record 0 and up to 10 more results
Query Parsing parse_request() method of WP_Query extracts query variables from URL Execute rewrite rules Pick off ?p=67 style http GET variables Match permalink structure Match keywords like “author” and “tag” WordCamp Chicago 9
Query Variables to SQL Query type: post by title, posts by category or tag, posts by date Variables for the query Slug values for category/tags Month/day numbers Explicit variable values?p=67 for post_id WordCamp Chicago 10
Simple Title Slug Parsing Rewrite matches root of permalink, extracts tail of URL as a title slug WordCamp Chicago 11 /2010/premio-sausage SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND YEAR(wp_posts.post_date)='2010' AND wp_posts.post_name = 'premio-sausage' AND wp_posts.post_type = 'post' ORDER BY wp_posts.post_date DESC
Graphs and JOIN Operations WordPress treats tags and categories as “terms”, mapped 1:N to posts Relational databases aren’t ideal for this INNER JOIN builds intermediate tables on common key values Following link in a social graph is equivalent to an INNER JOIN on tables of linked items WordCamp Chicago 12
WordPress Taxonomy Tables Term relationships table maps N:1 terms to each post Term taxonomy maps slugs 1:N to taxonomies Term table has slugs for URL mapping WordCamp Chicago 13 wp_term_relationshipsobject_idterm_taxonomy_id wp_postspost_id….post_date…  post_content wp_term_taxonomyterm_taxonomy_idterm_idtaxonomydescription wp_terms term_idnameslug
SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_postsINNER JOIN wp_term_relationships ON(wp_posts.ID = wp_term_relationships.object_id)INNER JOIN wp_term_taxonomy ON  (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)INNER JOIN wp_terms ON   (wp_term_taxonomy.term_id = wp_terms.term_id)WHERE 1=1 AND wp_term_taxonomy.taxonomy = 'post_tag' AND wp_terms.slug IN ('premio') AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10 Taxonomy Lookup WordCamp Chicago 14 /tag/premio
More on Canonical URLs Canonical URLs improve SEO WordPress is really good about generating 301 Redirects for non-standard URLs Example: URL doesn’t appear to match a permalink, WordPress does prediction Use “LIKE title%” in WHERE clause Matches “title” as initial substring with % wildcard WordCamp Chicago 15
Modifying the Query Brute force isn’t necessarily good Using query_posts() ignores all previous parsing, runs a new SQL query Filter query_vars Change default parsing (convert any day to a week’s worth of posts, for example) Actions parse_query & parse_request Access WP_Query object before execution is_xx() conditionals are already set WordCamp Chicago 16
SQL Generation Filters posts_where More explicit control over query variable to SQL grammar mapping posts_join Add or modify JOINS for other graph like relationships Many other filters Change grouping of results Change ordering of results WordCamp Chicago 17
Applications Stylized listings Category sorted alphabetically Use posts as listings of resources (jobs, clients, events) Custom URL slugs Add rewrite rules to match slug and set query variables Joining other social graphs Suggested/related content WordCamp Chicago 18
Template File Selection is_x() conditionals set in query parsing Used to drive template selection is_tag() looks for tag-slug, tag-id, then tag Full search hierarchy in Codex template_redirectaction Called in the template loader Add actions to override defaults WordCamp Chicago 19
HTML Generation Done in the_post() method Raw content retrieved from MySQL Short codes interpreted CSS applied Some caching plugins generate and store HTML, so YMMV WordCamp Chicago 20
Why Do You Care? User experience improvement JOINS are expensive Large table, repetitive SELECTs = slow Running query once keeps cache warm Category, permalink, title slug choices matter More CMS, less “blog” Alphabetical sort Adding taxonomy/social graph elements WordCamp Chicago 21
Blunt Self-Promotion Brad and David are here, too They’re significantly more WP literate than me This slide was more helpful yesterday 22 WordCamp Chicago
Resources Core files where SQL stuff happens query.php post.php canonical.php Template loader search path http://codex.wordpress.org/Template_Hierarchy WordCamp Chicago 23
Contact Hal Stern freeholdhal@gmail.com @freeholdhal http://snowmanonfire.com http://facebook.com/hal.stern http://slideshare.net/freeholdhal WordCamp Chicago 24

Weitere ähnliche Inhalte

Was ist angesagt?

Architecture of a search engine
Architecture of a search engineArchitecture of a search engine
Architecture of a search engineSylvain Utard
 
Internet with HTML
Internet with HTMLInternet with HTML
Internet with HTMLumesh patil
 
SharePoint Intelligence Introduction To Share Point Designer Workflows
SharePoint Intelligence Introduction To Share Point Designer WorkflowsSharePoint Intelligence Introduction To Share Point Designer Workflows
SharePoint Intelligence Introduction To Share Point Designer WorkflowsIvan Sanders
 
Google Search Techniques
Google Search TechniquesGoogle Search Techniques
Google Search TechniquesDuc Chau
 
How to create rss feed for your website
How to create  rss feed  for  your  websiteHow to create  rss feed  for  your  website
How to create rss feed for your websiteOM Maurya
 
How to create rss feed
How to create rss feedHow to create rss feed
How to create rss feedTanuja Talekar
 
How to build a custom search engine
How to build a custom search engineHow to build a custom search engine
How to build a custom search enginesearchbox-com
 
Mpl brownbag sept2011
Mpl brownbag sept2011Mpl brownbag sept2011
Mpl brownbag sept2011Jason Coleman
 
Google searching techniques
Google searching techniquesGoogle searching techniques
Google searching techniquesabbas mohd
 
Making The Most Out Of Google
Making The Most Out Of GoogleMaking The Most Out Of Google
Making The Most Out Of GoogleKieran Lamb
 
Customised Search With Google
Customised Search With GoogleCustomised Search With Google
Customised Search With GoogleDave Briggs
 

Was ist angesagt? (18)

Google Search Tips
Google Search TipsGoogle Search Tips
Google Search Tips
 
Architecture of a search engine
Architecture of a search engineArchitecture of a search engine
Architecture of a search engine
 
Internet with HTML
Internet with HTMLInternet with HTML
Internet with HTML
 
SharePoint Intelligence Introduction To Share Point Designer Workflows
SharePoint Intelligence Introduction To Share Point Designer WorkflowsSharePoint Intelligence Introduction To Share Point Designer Workflows
SharePoint Intelligence Introduction To Share Point Designer Workflows
 
Google Search Techniques
Google Search TechniquesGoogle Search Techniques
Google Search Techniques
 
Html5 final
Html5 finalHtml5 final
Html5 final
 
How to create rss feed for your website
How to create  rss feed  for  your  websiteHow to create  rss feed  for  your  website
How to create rss feed for your website
 
How to create rss feed
How to create rss feedHow to create rss feed
How to create rss feed
 
TUTORIAL DE CSS 2.0
TUTORIAL DE CSS 2.0TUTORIAL DE CSS 2.0
TUTORIAL DE CSS 2.0
 
Google Scholar
Google ScholarGoogle Scholar
Google Scholar
 
How to build a custom search engine
How to build a custom search engineHow to build a custom search engine
How to build a custom search engine
 
Google search tips
Google search tipsGoogle search tips
Google search tips
 
Mpl brownbag sept2011
Mpl brownbag sept2011Mpl brownbag sept2011
Mpl brownbag sept2011
 
Google power search
Google power searchGoogle power search
Google power search
 
Google searching techniques
Google searching techniquesGoogle searching techniques
Google searching techniques
 
xml sitemap
xml sitemapxml sitemap
xml sitemap
 
Making The Most Out Of Google
Making The Most Out Of GoogleMaking The Most Out Of Google
Making The Most Out Of Google
 
Customised Search With Google
Customised Search With GoogleCustomised Search With Google
Customised Search With Google
 

Andere mochten auch

Parsing strange v2
Parsing strange v2Parsing strange v2
Parsing strange v2Hal Stern
 
Parsing strange v4
Parsing strange v4Parsing strange v4
Parsing strange v4Hal Stern
 
Parsing strange v4
Parsing strange v4Parsing strange v4
Parsing strange v4Hal Stern
 
Parsing strange v3
Parsing strange v3Parsing strange v3
Parsing strange v3Hal Stern
 
Ogra S1 2010 Op Competitiveness Part1
Ogra S1 2010 Op Competitiveness Part1Ogra S1 2010 Op Competitiveness Part1
Ogra S1 2010 Op Competitiveness Part1Veselina Nikolova
 
Shades team in action
Shades team in actionShades team in action
Shades team in actionDonna Roberts
 
Stephen Rathinaraj Corr
Stephen Rathinaraj   CorrStephen Rathinaraj   Corr
Stephen Rathinaraj Corrfarsiya
 
Stephen 205 (1)
Stephen 205 (1)Stephen 205 (1)
Stephen 205 (1)farsiya
 
Entr sme10 the_secret_of_success_-_the_many_faces_of_european_entrepreneurshi...
Entr sme10 the_secret_of_success_-_the_many_faces_of_european_entrepreneurshi...Entr sme10 the_secret_of_success_-_the_many_faces_of_european_entrepreneurshi...
Entr sme10 the_secret_of_success_-_the_many_faces_of_european_entrepreneurshi...Veselina Nikolova
 
Teoria de control presentacion
Teoria de control presentacionTeoria de control presentacion
Teoria de control presentacioncesar
 
100512074 analisis-de-respuesta-transitoria-docx
100512074 analisis-de-respuesta-transitoria-docx100512074 analisis-de-respuesta-transitoria-docx
100512074 analisis-de-respuesta-transitoria-docxcesar
 

Andere mochten auch (17)

Faces all
Faces allFaces all
Faces all
 
ЕГДБ
ЕГДБЕГДБ
ЕГДБ
 
Parsing strange v2
Parsing strange v2Parsing strange v2
Parsing strange v2
 
Ogra s3-2010 success
Ogra s3-2010 successOgra s3-2010 success
Ogra s3-2010 success
 
Parsing strange v4
Parsing strange v4Parsing strange v4
Parsing strange v4
 
11 13
11 1311 13
11 13
 
Presentation sofia
Presentation sofiaPresentation sofia
Presentation sofia
 
Parsing strange v4
Parsing strange v4Parsing strange v4
Parsing strange v4
 
Parsing strange v3
Parsing strange v3Parsing strange v3
Parsing strange v3
 
Ogra S1 2010 Op Competitiveness Part1
Ogra S1 2010 Op Competitiveness Part1Ogra S1 2010 Op Competitiveness Part1
Ogra S1 2010 Op Competitiveness Part1
 
Ogra s4-2010 tenders
Ogra s4-2010 tendersOgra s4-2010 tenders
Ogra s4-2010 tenders
 
Shades team in action
Shades team in actionShades team in action
Shades team in action
 
Stephen Rathinaraj Corr
Stephen Rathinaraj   CorrStephen Rathinaraj   Corr
Stephen Rathinaraj Corr
 
Stephen 205 (1)
Stephen 205 (1)Stephen 205 (1)
Stephen 205 (1)
 
Entr sme10 the_secret_of_success_-_the_many_faces_of_european_entrepreneurshi...
Entr sme10 the_secret_of_success_-_the_many_faces_of_european_entrepreneurshi...Entr sme10 the_secret_of_success_-_the_many_faces_of_european_entrepreneurshi...
Entr sme10 the_secret_of_success_-_the_many_faces_of_european_entrepreneurshi...
 
Teoria de control presentacion
Teoria de control presentacionTeoria de control presentacion
Teoria de control presentacion
 
100512074 analisis-de-respuesta-transitoria-docx
100512074 analisis-de-respuesta-transitoria-docx100512074 analisis-de-respuesta-transitoria-docx
100512074 analisis-de-respuesta-transitoria-docx
 

Ähnlich wie Parsing strange v1.1

Parsing strange v3
Parsing strange v3Parsing strange v3
Parsing strange v3Hal Stern
 
Assignment 2 - Power drill Grapevine "It's like Yik Yak, but for opinions ab...
Assignment 2 - Power drill Grapevine  "It's like Yik Yak, but for opinions ab...Assignment 2 - Power drill Grapevine  "It's like Yik Yak, but for opinions ab...
Assignment 2 - Power drill Grapevine "It's like Yik Yak, but for opinions ab...MATCHmaster
 
The WordPress University 2012
The WordPress University 2012The WordPress University 2012
The WordPress University 2012Stephanie Leary
 
Building social and RESTful frameworks
Building social and RESTful frameworksBuilding social and RESTful frameworks
Building social and RESTful frameworksbrendonschwartz
 
38_Spotkanie_PLSSUGweWroclawiu_KilkaSłów_ApexSQL_FreeTools
38_Spotkanie_PLSSUGweWroclawiu_KilkaSłów_ApexSQL_FreeTools38_Spotkanie_PLSSUGweWroclawiu_KilkaSłów_ApexSQL_FreeTools
38_Spotkanie_PLSSUGweWroclawiu_KilkaSłów_ApexSQL_FreeToolsTobias Koprowski
 
PV Standard Search Query
PV Standard Search QueryPV Standard Search Query
PV Standard Search QueryProdigyView
 
Customizing SharePoint 2013 search display templates
Customizing SharePoint 2013 search display templatesCustomizing SharePoint 2013 search display templates
Customizing SharePoint 2013 search display templatesTony Testa
 
Cegonsoft-Php training institute Bangalore
Cegonsoft-Php training institute BangaloreCegonsoft-Php training institute Bangalore
Cegonsoft-Php training institute Bangaloredhivyas19
 
Troubleshooting Technical SEO Problems - Patrick Stox - Raleigh SEO Meetup
Troubleshooting Technical SEO Problems - Patrick Stox - Raleigh SEO MeetupTroubleshooting Technical SEO Problems - Patrick Stox - Raleigh SEO Meetup
Troubleshooting Technical SEO Problems - Patrick Stox - Raleigh SEO Meetuppatrickstox
 
Advanced Drupal SEO - Beginner to Expert in 60 Minutes
Advanced Drupal SEO - Beginner to Expert in 60 MinutesAdvanced Drupal SEO - Beginner to Expert in 60 Minutes
Advanced Drupal SEO - Beginner to Expert in 60 MinutesTom McCracken
 
Spsvb Developer Intro to SharePoint Search
Spsvb   Developer Intro to SharePoint SearchSpsvb   Developer Intro to SharePoint Search
Spsvb Developer Intro to SharePoint SearchMichael Oryszak
 
MIS5101 WK10 Outcome Measures
MIS5101 WK10 Outcome MeasuresMIS5101 WK10 Outcome Measures
MIS5101 WK10 Outcome MeasuresSteven Johnson
 
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
 
Child Themes in WordPress
Child Themes in WordPressChild Themes in WordPress
Child Themes in WordPressJeff Cohan
 
Spca2014 search workshop niaulin
Spca2014 search workshop niaulinSpca2014 search workshop niaulin
Spca2014 search workshop niaulinNCCOMMS
 
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
 

Ähnlich wie Parsing strange v1.1 (20)

Parsing strange v3
Parsing strange v3Parsing strange v3
Parsing strange v3
 
Article16
Article16Article16
Article16
 
Assignment 2 - Power drill Grapevine "It's like Yik Yak, but for opinions ab...
Assignment 2 - Power drill Grapevine  "It's like Yik Yak, but for opinions ab...Assignment 2 - Power drill Grapevine  "It's like Yik Yak, but for opinions ab...
Assignment 2 - Power drill Grapevine "It's like Yik Yak, but for opinions ab...
 
The WordPress University 2012
The WordPress University 2012The WordPress University 2012
The WordPress University 2012
 
Building social and RESTful frameworks
Building social and RESTful frameworksBuilding social and RESTful frameworks
Building social and RESTful frameworks
 
38_Spotkanie_PLSSUGweWroclawiu_KilkaSłów_ApexSQL_FreeTools
38_Spotkanie_PLSSUGweWroclawiu_KilkaSłów_ApexSQL_FreeTools38_Spotkanie_PLSSUGweWroclawiu_KilkaSłów_ApexSQL_FreeTools
38_Spotkanie_PLSSUGweWroclawiu_KilkaSłów_ApexSQL_FreeTools
 
PV Standard Search Query
PV Standard Search QueryPV Standard Search Query
PV Standard Search Query
 
Customizing SharePoint 2013 search display templates
Customizing SharePoint 2013 search display templatesCustomizing SharePoint 2013 search display templates
Customizing SharePoint 2013 search display templates
 
Cegonsoft-Php training institute Bangalore
Cegonsoft-Php training institute BangaloreCegonsoft-Php training institute Bangalore
Cegonsoft-Php training institute Bangalore
 
Troubleshooting Technical SEO Problems - Patrick Stox - Raleigh SEO Meetup
Troubleshooting Technical SEO Problems - Patrick Stox - Raleigh SEO MeetupTroubleshooting Technical SEO Problems - Patrick Stox - Raleigh SEO Meetup
Troubleshooting Technical SEO Problems - Patrick Stox - Raleigh SEO Meetup
 
Advanced Drupal SEO - Beginner to Expert in 60 Minutes
Advanced Drupal SEO - Beginner to Expert in 60 MinutesAdvanced Drupal SEO - Beginner to Expert in 60 Minutes
Advanced Drupal SEO - Beginner to Expert in 60 Minutes
 
Spsvb Developer Intro to SharePoint Search
Spsvb   Developer Intro to SharePoint SearchSpsvb   Developer Intro to SharePoint Search
Spsvb Developer Intro to SharePoint Search
 
MIS5101 WK10 Outcome Measures
MIS5101 WK10 Outcome MeasuresMIS5101 WK10 Outcome Measures
MIS5101 WK10 Outcome Measures
 
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
 
Child Themes in WordPress
Child Themes in WordPressChild Themes in WordPress
Child Themes in WordPress
 
Spca2014 search workshop niaulin
Spca2014 search workshop niaulinSpca2014 search workshop niaulin
Spca2014 search workshop niaulin
 
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
 
Php mysql 2
Php mysql 2Php mysql 2
Php mysql 2
 

Kürzlich hochgeladen

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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 slidevu2urc
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
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...Miguel Araújo
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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 BusinessPixlogix Infotech
 

Kürzlich hochgeladen (20)

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 

Parsing strange v1.1

  • 1. Parsing Strange:URL to SQL to HTML Hal Stern http://snowmanonfire.com headshot by Richard Stevenshttp://dieselsweeties.com
  • 2. Why Do You Care? Database performance = user experience A little database expertise goes a long way Use taxonomies for more than sidebar lists WordPress is a powerful CMS Change default behaviors Defy the common wisdom Integrate other content sources/filters WordCamp Chicago 2
  • 3. Disclaimers I’m somewhat social, for Jersey I’m (old) old school If using PHP echo gives you hives……take a Benadryl now If “INNER JOIN” makes you giggle, you’re in the wrong session/conference/fantasy I suck at art and design 3 WordCamp Chicago
  • 4. Flow of Control Web server URL manipulation Real file or permalink URL? URL to query variables What to display? Tag? Post? Category? Query variables to SQL generation How exactly to get that content? Template file selection How will content be displayed? Content manipulation 4 WordCamp Chicago
  • 5. Whose File Is This? User URL request passed to web server Web server checks.htaccessfile WP install root Other .htaccessfiles may interfere Basic rewriting rules:If file or directory URL doesn’t exist, start WordPress via index.php WordCamp Chicago 5 <IfModulemod_rewrite.c> RewriteEngine On RewriteBase /whereyouputWordPress/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
  • 6. What Happens Before The Loop Parse URL into a query Set conditionals & select templates Execute the query & cache results Run the Loop:<?phpif (have_posts()) : while (have_posts()) : the_post(); //loop contentendwhile;endif;?> WordCamp Chicago 6
  • 7. Examining the Query String SQL passed to MySQL in WP_Query object’s request element Brute force: edit theme footer.phpto see main loop’s query for displayed page WordCamp Chicago 7 <?php global $wp_query; echo ”SQL for this page "; echo $wp_query->request; echo "<br>"; ?>
  • 8. SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post’ AND(wp_posts.post_status = 'publish' ORwp_posts.post_status = 'private’)ORDER BY wp_posts.post_date DESC LIMIT 0, 10 “Home Page” Query Deconstruction WordCamp Chicago 8 Get all fields from posts table, but limit number of returned rows Only get posts, and those that are published or private to the user Sort the results by date in descending order Start results starting with record 0 and up to 10 more results
  • 9. Query Parsing parse_request() method of WP_Query extracts query variables from URL Execute rewrite rules Pick off ?p=67 style http GET variables Match permalink structure Match keywords like “author” and “tag” WordCamp Chicago 9
  • 10. Query Variables to SQL Query type: post by title, posts by category or tag, posts by date Variables for the query Slug values for category/tags Month/day numbers Explicit variable values?p=67 for post_id WordCamp Chicago 10
  • 11. Simple Title Slug Parsing Rewrite matches root of permalink, extracts tail of URL as a title slug WordCamp Chicago 11 /2010/premio-sausage SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND YEAR(wp_posts.post_date)='2010' AND wp_posts.post_name = 'premio-sausage' AND wp_posts.post_type = 'post' ORDER BY wp_posts.post_date DESC
  • 12. Graphs and JOIN Operations WordPress treats tags and categories as “terms”, mapped 1:N to posts Relational databases aren’t ideal for this INNER JOIN builds intermediate tables on common key values Following link in a social graph is equivalent to an INNER JOIN on tables of linked items WordCamp Chicago 12
  • 13. WordPress Taxonomy Tables Term relationships table maps N:1 terms to each post Term taxonomy maps slugs 1:N to taxonomies Term table has slugs for URL mapping WordCamp Chicago 13 wp_term_relationshipsobject_idterm_taxonomy_id wp_postspost_id….post_date… post_content wp_term_taxonomyterm_taxonomy_idterm_idtaxonomydescription wp_terms term_idnameslug
  • 14. SELECT SQL_CALC_FOUND_ROWS wp_posts.* FROM wp_postsINNER JOIN wp_term_relationships ON(wp_posts.ID = wp_term_relationships.object_id)INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)INNER JOIN wp_terms ON (wp_term_taxonomy.term_id = wp_terms.term_id)WHERE 1=1 AND wp_term_taxonomy.taxonomy = 'post_tag' AND wp_terms.slug IN ('premio') AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10 Taxonomy Lookup WordCamp Chicago 14 /tag/premio
  • 15. More on Canonical URLs Canonical URLs improve SEO WordPress is really good about generating 301 Redirects for non-standard URLs Example: URL doesn’t appear to match a permalink, WordPress does prediction Use “LIKE title%” in WHERE clause Matches “title” as initial substring with % wildcard WordCamp Chicago 15
  • 16. Modifying the Query Brute force isn’t necessarily good Using query_posts() ignores all previous parsing, runs a new SQL query Filter query_vars Change default parsing (convert any day to a week’s worth of posts, for example) Actions parse_query & parse_request Access WP_Query object before execution is_xx() conditionals are already set WordCamp Chicago 16
  • 17. SQL Generation Filters posts_where More explicit control over query variable to SQL grammar mapping posts_join Add or modify JOINS for other graph like relationships Many other filters Change grouping of results Change ordering of results WordCamp Chicago 17
  • 18. Applications Stylized listings Category sorted alphabetically Use posts as listings of resources (jobs, clients, events) Custom URL slugs Add rewrite rules to match slug and set query variables Joining other social graphs Suggested/related content WordCamp Chicago 18
  • 19. Template File Selection is_x() conditionals set in query parsing Used to drive template selection is_tag() looks for tag-slug, tag-id, then tag Full search hierarchy in Codex template_redirectaction Called in the template loader Add actions to override defaults WordCamp Chicago 19
  • 20. HTML Generation Done in the_post() method Raw content retrieved from MySQL Short codes interpreted CSS applied Some caching plugins generate and store HTML, so YMMV WordCamp Chicago 20
  • 21. Why Do You Care? User experience improvement JOINS are expensive Large table, repetitive SELECTs = slow Running query once keeps cache warm Category, permalink, title slug choices matter More CMS, less “blog” Alphabetical sort Adding taxonomy/social graph elements WordCamp Chicago 21
  • 22. Blunt Self-Promotion Brad and David are here, too They’re significantly more WP literate than me This slide was more helpful yesterday 22 WordCamp Chicago
  • 23. Resources Core files where SQL stuff happens query.php post.php canonical.php Template loader search path http://codex.wordpress.org/Template_Hierarchy WordCamp Chicago 23
  • 24. Contact Hal Stern freeholdhal@gmail.com @freeholdhal http://snowmanonfire.com http://facebook.com/hal.stern http://slideshare.net/freeholdhal WordCamp Chicago 24

Hinweis der Redaktion

  1. SQL_CALC_FOUND_ROWS limits the number of returned rows via the LIMIT clause, and ensures that you don’t tax MySQL,Perform immense queries (SMOF has 600 post entries)WHERE 1=1 is for building compound where clauses; ensures there’s no degenerate caseType=post versus revision; status publish/private versus draft, trash
  2. Look at rewrite.php, and canonical.php (more on that later)Default terms of “tag” and “category” can be changed in the Settings/Permalinks section of the Dashboard
  3. Separate namespaces for pages and postsWhat about parent pages?In this example the permalink structure is %year%/%title%
  4. Three joins needed to build the full cartesian product of related tables.Get all of the terms that have a slug of “premio”, and find out what taxonomies they’re inGet the taxonomies that are post tags, and find all taxonomy object ids (that are post tags of slug “premio”)Get all of the posts that have this object id associated with them from term_relationshipsOrder the final table by post date,starting with the most recent (0) and getting 10 of them.
  5. Don’t want multiple URLs pointing to the same page, so canonical parsing cleans them up