0
0
Wordpressframework~10 mins

Template hierarchy in Wordpress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to load the main template file in WordPress.

Wordpress
get_template_part('[1]');
Drag options to blanks, or click blank then click option'
Aheader
Bindex
Cfooter
Dsidebar
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'header' or 'footer' instead of 'index' loads other template parts, not the main one.
Forgetting to pass the template name as a string.
2fill in blank
medium

Complete the code to load the template for a single post in WordPress.

Wordpress
get_template_part('[1]');
Drag options to blanks, or click blank then click option'
Asingle
Bpage
Carchive
Dsearch
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'page' loads the page template, not single posts.
Using 'archive' loads archive pages, not single posts.
3fill in blank
hard

Fix the error in the code to load the category template correctly.

Wordpress
get_template_part('[1]');
Drag options to blanks, or click blank then click option'
Acategory
Bcategories
Ccat
Darchive-category
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'categories' or 'cat' which do not match the template file name.
Using 'archive-category' which is not a standard template part.
4fill in blank
hard

Fill both blanks to create a conditional that loads the author template only on author archive pages.

Wordpress
if (is_[1]()) {
  get_template_part('[2]');
}
Drag options to blanks, or click blank then click option'
Aauthor
Barchive
Dsingle
Attempts:
3 left
💡 Hint
Common Mistakes
Using is_archive() which is more general and not specific to authors.
Loading the wrong template part like 'single' instead of 'author'.
5fill in blank
hard

Fill all three blanks to create a custom loop that loads the content template only for posts in the 'news' category.

Wordpress
if (have_posts()) {
  while (have_posts()) {
    the_post();
    if (in_category('[1]')) {
      get_template_part('[2]', '[3]');
    }
  }
}
Drag options to blanks, or click blank then click option'
Anews
Bcontent
Dsingle
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong category slug or template part names.
Not passing the second argument to get_template_part for variations.