SlideShare a Scribd company logo
1 of 23
Download to read offline
How Does get_template_part
Works In Twenty Ten Theme
        By: Rozani Ghani

       http://rozanighani.com/
What Exactly
       GET_template_part is?
• get_template_part is used to load a template
  part into a template (other than header,
  sidebar, footer)
• get_template_part is used for child theme
  development but actually is not just for child
  theme development only, is there more than
  that.
Let See how GET_template_part
         is originated?
• We see how get_template_part works.
• This example may vary with how developer
  perception but this is just to illustrate how the
  the get_template_part works.
• I use index.html as the very famous example.
• As a clear example, I use the index.php in
  Twenty Ten Theme.
Index.html
• A wordpress index.html mostly consist of
  these 4 basic template php files: header.php,
  index.php, sidebar.php and also footer.php.
• I visualize these files in order to understand
  get_template_part is.
How Does get_template_part
    Works In Twenty Ten Theme




By: Rozani Ghani     http://rozanighani.com/
Header.php




         Index.html
                                 Index.php       Sidebar.php




• We break the index.html into
the basic wordpress template
files.
                                        Footer.php
• We break the index.html into the basic wordpress template files. That is header.php,
index.php, sidebar.php and footer.php



                                                              Header.php




            Index.html
                                                       Index.php        Sidebar.php




                                                               Footer.php
• We break the php into standard WordPress Codex tags.




           Header.php                                     <?php get_header(); ?>




                                                                            <?php
    Index.php         Sidebar.php                        Index.php      get_sidebar();
                                                                              ?>




            Footer.php                                    <?php get_footer(); ?>
How About index.php?
 <?php get_header(); ?>
                                 • Suppose there is a code to
                                   replace index.php that is
                                   <?php get_index (); ?>
                                 • After search in the
                                   WordPress codex, <?php
                   <?php           get_index (); ?> is not exist.
Index.php      get_sidebar();
                     ?>
                                 • I prefer not to discuss
                                   get_index because
                                   WordPress already done
                                   stuff to make the index.php
                                   working smoothly.
 <?php get_footer(); ?>
Next…
•   We going directly to get_template_part.
•   But first, we going to understand this example.
•   <?php get_template_part( $slug, $name ); ?>
•   <?php get_template_part( 'loop', 'index' ); ?>
•   What the heck are these?
What is $slug and $name?
• At the 1st sight, I don’t really understand what
  $slug and $name are.
• But, I take them as these:
   $slug as $ parent
   $name as $child
• As I take them like that, it much easier to
  understand get_template_part and very much
  of child theme
Recall…
• <?php get_template_part( $slug, $name ); ?>
  can be written also
  is <?php get_template_part( $slug ); ?>
• We going to convert those code such as
  get_header into get_template_part (‘header’)
We going to convert those code such as get_header into
               get_template_part (‘header’)

                                                <?php
 <?php get_header(); ?>
                                    get_template_part(‘header’); ?>




                                                           <?php
                   <?php                  <?php
                                                       get_template_
Index.php      get_sidebar();      get_template_part
                                                       part(‘sidebar’)
                     ?>               (‘index’); ?>
                                                             ; ?>




                                                <?php
 <?php get_footer(); ?>
                                     get_template_part(‘footer’); ?>
We can conclude that the get_template_part works like this.


                          <?php get_header(); ?>




<?php get_template_part(‘index’); ?>               <?php get_sidebar(); ?>




                          <?php get_footer(); ?>
The real index.php of Twenty Ten Theme looks like this.


                                    <?php get_header(); ?>



<div id="container">
          <div id="content" role="main">



<?php get_template_part( 'loop', 'index' );?>
                                                             <?php get_sidebar(); ?>




          </div><!-- #content -->
</div><!-- #container -->

                                    <?php get_footer(); ?>
Index.php of Twenty Ten Theme
• Its look this:




• The index.php is using <?php
  get_template_part (‘loop’, ‘index’); ?>
Why?
• <?php get_template_part (‘loop’, ‘index’); ?>
  is used to load loop-index.php.
• What if loop-index.php not exists?
• get_template_part will load loop.php
Back to $slug and $name
Coding Technically           File Rename Technically
• Codex:                     • Codex:
• <?php get_template_part(   • $slug-$name.php
  $slug, $name ); ?>
• Example:                   • Example:
• <?php get_template_part(   • loop-index.php
  'loop', 'index' ); ?>
                             • must have “-” between
                               $slug and $name
Why $parent and $child?
• To me, it is easier to understand and not much
  confused.
• Back to loop-index.php, this file already a child
  php file.
• If <?php get_template_part (‘loop’, ‘index’); ?>
  try to load loop-index.php but it fail, it will
  load her parent php file which is loop.php
• Agree ?
How Does get_template_part
    Works In Twenty Ten Theme




By: Rozani Ghani     http://rozanighani.com/
Another Example Much Similar
• If you have Twenty Ten Theme, you should the
  the footer.php file. See this:



• Much prettier right? But it is for sidebar.
• That code will load sidebar-footer.php
sidebar-footer.php
•   <?php get_sidebar( 'footer' );?>
•   is similar to
•   <?php get_template_part ( 'footer' );?>
•   Why?
•   Look the php file which is sidebar-footer.php

• Revise back what you have learn.
How Does get_template_part
    Works In Twenty Ten Theme




By: Rozani Ghani     http://rozanighani.com/

More Related Content

What's hot

Real World Dependency Injection - oscon13
Real World Dependency Injection - oscon13Real World Dependency Injection - oscon13
Real World Dependency Injection - oscon13
Stephan Hochdörfer
 
5 Reasons To Love CodeIgniter
5 Reasons To Love CodeIgniter5 Reasons To Love CodeIgniter
5 Reasons To Love CodeIgniter
nicdev
 

What's hot (19)

Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919
 
A Phing fairy tale - ConFoo13
A Phing fairy tale - ConFoo13A Phing fairy tale - ConFoo13
A Phing fairy tale - ConFoo13
 
Introduction to WordPress Theme Development
Introduction to WordPress Theme DevelopmentIntroduction to WordPress Theme Development
Introduction to WordPress Theme Development
 
Wordpress(css,php,js,ajax)
Wordpress(css,php,js,ajax)Wordpress(css,php,js,ajax)
Wordpress(css,php,js,ajax)
 
Demystifying WordPress Conditional Tags
Demystifying WordPress Conditional TagsDemystifying WordPress Conditional Tags
Demystifying WordPress Conditional Tags
 
Grok Drupal (7) Theming
Grok Drupal (7) ThemingGrok Drupal (7) Theming
Grok Drupal (7) Theming
 
Grok Drupal (7) Theming - 2011 Feb update
Grok Drupal (7) Theming - 2011 Feb updateGrok Drupal (7) Theming - 2011 Feb update
Grok Drupal (7) Theming - 2011 Feb update
 
PSD to WordPress
PSD to WordPressPSD to WordPress
PSD to WordPress
 
Grok Drupal (7) Theming (presented at DrupalCon San Francisco)
Grok Drupal (7) Theming (presented at DrupalCon San Francisco)Grok Drupal (7) Theming (presented at DrupalCon San Francisco)
Grok Drupal (7) Theming (presented at DrupalCon San Francisco)
 
Real World Dependency Injection - oscon13
Real World Dependency Injection - oscon13Real World Dependency Injection - oscon13
Real World Dependency Injection - oscon13
 
Customizing WordPress Themes
Customizing WordPress ThemesCustomizing WordPress Themes
Customizing WordPress Themes
 
I Love codeigniter, You?
I Love codeigniter, You?I Love codeigniter, You?
I Love codeigniter, You?
 
Builing a WordPress Theme
Builing a WordPress ThemeBuiling a WordPress Theme
Builing a WordPress Theme
 
Rails 101
Rails 101Rails 101
Rails 101
 
HTML 5 Basics Part One
HTML 5 Basics Part OneHTML 5 Basics Part One
HTML 5 Basics Part One
 
Perch CMS Summit: Perch Template Tips and Tricks
Perch CMS Summit: Perch Template Tips and TricksPerch CMS Summit: Perch Template Tips and Tricks
Perch CMS Summit: Perch Template Tips and Tricks
 
Joomla! Day Chicago 2011 - Templating the right way - Jonathan Shroyer
Joomla! Day Chicago 2011 - Templating the right way - Jonathan ShroyerJoomla! Day Chicago 2011 - Templating the right way - Jonathan Shroyer
Joomla! Day Chicago 2011 - Templating the right way - Jonathan Shroyer
 
Getting to know perch — and perch runway!
Getting to know perch — and perch runway!Getting to know perch — and perch runway!
Getting to know perch — and perch runway!
 
5 Reasons To Love CodeIgniter
5 Reasons To Love CodeIgniter5 Reasons To Love CodeIgniter
5 Reasons To Love CodeIgniter
 

Viewers also liked (9)

Howdoesgettemplatepartworksintwentytentheme 110123234953-phpapp02
Howdoesgettemplatepartworksintwentytentheme 110123234953-phpapp02Howdoesgettemplatepartworksintwentytentheme 110123234953-phpapp02
Howdoesgettemplatepartworksintwentytentheme 110123234953-phpapp02
 
App211 techdays 2013 Windows 8 concevoir des applications efficaces et perfor...
App211 techdays 2013 Windows 8 concevoir des applications efficaces et perfor...App211 techdays 2013 Windows 8 concevoir des applications efficaces et perfor...
App211 techdays 2013 Windows 8 concevoir des applications efficaces et perfor...
 
100 tips for building and maintaining a successful blog
100 tips for building and maintaining a successful blog100 tips for building and maintaining a successful blog
100 tips for building and maintaining a successful blog
 
Photo Album2 3
Photo Album2 3Photo Album2 3
Photo Album2 3
 
salkdjfhdjkghdfkjh
salkdjfhdjkghdfkjhsalkdjfhdjkghdfkjh
salkdjfhdjkghdfkjh
 
Progamme XKE Janvier 2012
Progamme XKE Janvier 2012Progamme XKE Janvier 2012
Progamme XKE Janvier 2012
 
Concevoir des applications SharePoint basées sur la recherche
Concevoir des applications SharePoint basées sur la rechercheConcevoir des applications SharePoint basées sur la recherche
Concevoir des applications SharePoint basées sur la recherche
 
Rails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity PresentationRails 3 And The Real Secret To High Productivity Presentation
Rails 3 And The Real Secret To High Productivity Presentation
 
aergserga
aergsergaaergserga
aergserga
 

Similar to How does get template part works in twenty ten theme

Word press templates
Word press templatesWord press templates
Word press templates
Dan Phiffer
 
Wordpress Custom Child theme
Wordpress Custom Child themeWordpress Custom Child theme
Wordpress Custom Child theme
YouSaf HasSan
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1
Yoav Farhi
 

Similar to How does get template part works in twenty ten theme (20)

Theming 101
Theming 101Theming 101
Theming 101
 
Word Camp Fukuoka2010
Word Camp Fukuoka2010Word Camp Fukuoka2010
Word Camp Fukuoka2010
 
Word press templates
Word press templatesWord press templates
Word press templates
 
WordPress Theme Workshop: Part 4
WordPress Theme Workshop: Part 4WordPress Theme Workshop: Part 4
WordPress Theme Workshop: Part 4
 
The Loop
The LoopThe Loop
The Loop
 
Crash Course in Theme Surgery
Crash Course in Theme SurgeryCrash Course in Theme Surgery
Crash Course in Theme Surgery
 
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
WordPress theme development from scratch : ICT MeetUp 2013 NepalWordPress theme development from scratch : ICT MeetUp 2013 Nepal
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
 
The Way to Theme Enlightenment
The Way to Theme EnlightenmentThe Way to Theme Enlightenment
The Way to Theme Enlightenment
 
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
 
Anatomy of a Wordpress theme
Anatomy of a Wordpress themeAnatomy of a Wordpress theme
Anatomy of a Wordpress theme
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
 
How to make a WordPress theme
How to make a WordPress themeHow to make a WordPress theme
How to make a WordPress theme
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress development
 
The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017
 
Wordpress Custom Child theme
Wordpress Custom Child themeWordpress Custom Child theme
Wordpress Custom Child theme
 
20110820 header new style
20110820 header new style20110820 header new style
20110820 header new style
 
&lt;?php + WordPress
&lt;?php + WordPress&lt;?php + WordPress
&lt;?php + WordPress
 
Introduction to WordPress Plugin Development, WordCamp North Canton, 2015
Introduction to WordPress Plugin Development, WordCamp North Canton, 2015Introduction to WordPress Plugin Development, WordCamp North Canton, 2015
Introduction to WordPress Plugin Development, WordCamp North Canton, 2015
 
WordPress
WordPressWordPress
WordPress
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1
 

How does get template part works in twenty ten theme

  • 1. How Does get_template_part Works In Twenty Ten Theme By: Rozani Ghani http://rozanighani.com/
  • 2. What Exactly GET_template_part is? • get_template_part is used to load a template part into a template (other than header, sidebar, footer) • get_template_part is used for child theme development but actually is not just for child theme development only, is there more than that.
  • 3. Let See how GET_template_part is originated? • We see how get_template_part works. • This example may vary with how developer perception but this is just to illustrate how the the get_template_part works. • I use index.html as the very famous example. • As a clear example, I use the index.php in Twenty Ten Theme.
  • 4. Index.html • A wordpress index.html mostly consist of these 4 basic template php files: header.php, index.php, sidebar.php and also footer.php. • I visualize these files in order to understand get_template_part is.
  • 5. How Does get_template_part Works In Twenty Ten Theme By: Rozani Ghani http://rozanighani.com/
  • 6. Header.php Index.html Index.php Sidebar.php • We break the index.html into the basic wordpress template files. Footer.php
  • 7. • We break the index.html into the basic wordpress template files. That is header.php, index.php, sidebar.php and footer.php Header.php Index.html Index.php Sidebar.php Footer.php
  • 8. • We break the php into standard WordPress Codex tags. Header.php <?php get_header(); ?> <?php Index.php Sidebar.php Index.php get_sidebar(); ?> Footer.php <?php get_footer(); ?>
  • 9. How About index.php? <?php get_header(); ?> • Suppose there is a code to replace index.php that is <?php get_index (); ?> • After search in the WordPress codex, <?php <?php get_index (); ?> is not exist. Index.php get_sidebar(); ?> • I prefer not to discuss get_index because WordPress already done stuff to make the index.php working smoothly. <?php get_footer(); ?>
  • 10. Next… • We going directly to get_template_part. • But first, we going to understand this example. • <?php get_template_part( $slug, $name ); ?> • <?php get_template_part( 'loop', 'index' ); ?> • What the heck are these?
  • 11. What is $slug and $name? • At the 1st sight, I don’t really understand what $slug and $name are. • But, I take them as these:  $slug as $ parent  $name as $child • As I take them like that, it much easier to understand get_template_part and very much of child theme
  • 12. Recall… • <?php get_template_part( $slug, $name ); ?> can be written also is <?php get_template_part( $slug ); ?> • We going to convert those code such as get_header into get_template_part (‘header’)
  • 13. We going to convert those code such as get_header into get_template_part (‘header’) <?php <?php get_header(); ?> get_template_part(‘header’); ?> <?php <?php <?php get_template_ Index.php get_sidebar(); get_template_part part(‘sidebar’) ?> (‘index’); ?> ; ?> <?php <?php get_footer(); ?> get_template_part(‘footer’); ?>
  • 14. We can conclude that the get_template_part works like this. <?php get_header(); ?> <?php get_template_part(‘index’); ?> <?php get_sidebar(); ?> <?php get_footer(); ?>
  • 15. The real index.php of Twenty Ten Theme looks like this. <?php get_header(); ?> <div id="container"> <div id="content" role="main"> <?php get_template_part( 'loop', 'index' );?> <?php get_sidebar(); ?> </div><!-- #content --> </div><!-- #container --> <?php get_footer(); ?>
  • 16. Index.php of Twenty Ten Theme • Its look this: • The index.php is using <?php get_template_part (‘loop’, ‘index’); ?>
  • 17. Why? • <?php get_template_part (‘loop’, ‘index’); ?> is used to load loop-index.php. • What if loop-index.php not exists? • get_template_part will load loop.php
  • 18. Back to $slug and $name Coding Technically File Rename Technically • Codex: • Codex: • <?php get_template_part( • $slug-$name.php $slug, $name ); ?> • Example: • Example: • <?php get_template_part( • loop-index.php 'loop', 'index' ); ?> • must have “-” between $slug and $name
  • 19. Why $parent and $child? • To me, it is easier to understand and not much confused. • Back to loop-index.php, this file already a child php file. • If <?php get_template_part (‘loop’, ‘index’); ?> try to load loop-index.php but it fail, it will load her parent php file which is loop.php • Agree ?
  • 20. How Does get_template_part Works In Twenty Ten Theme By: Rozani Ghani http://rozanighani.com/
  • 21. Another Example Much Similar • If you have Twenty Ten Theme, you should the the footer.php file. See this: • Much prettier right? But it is for sidebar. • That code will load sidebar-footer.php
  • 22. sidebar-footer.php • <?php get_sidebar( 'footer' );?> • is similar to • <?php get_template_part ( 'footer' );?> • Why? • Look the php file which is sidebar-footer.php • Revise back what you have learn.
  • 23. How Does get_template_part Works In Twenty Ten Theme By: Rozani Ghani http://rozanighani.com/