Comments

Used the comments.php file from Underscores as it’s a pretty complex load of code. So, created the file, then pulled it in to content.php using the comments_template() template tag.

The code caters for closing the comments if this is set in the WP dashboard. Can also use the tag comments_open() within a condition, so that comments only display if they are open; if they are closed comments won’t display at all.

singular.php

A new template file! page.php, single.php and attachement.php all fall back to singular.php if WordPress can’t find them. singular.php falls back to index.php.

Zac points out that singular.php may be redundant if your them contains page.php, single.php and attachement.php, and / or if singular.php contains the same code as index.php

using modular files

Modular files can be reused in different places, and are often small and focussed on one specific thing.

So: saved content that goes inside the loop up until the “endwhile” in content.php and saved that inside a folder called template-parts. Content that goes between “endwhile” and “endif” goes in a file called content-none.php. Then used get_template_part() in index.php to pull in the appropriate content.

registering widget areas

Well, the first thing I learned in today’s lesson is that a sidebar should more actually be called a “widget area”, as a sidebar can go anywhere, and it’s main purpose is to contain widgets. Interesting!

Then, I used register_sidebar() to register different widget areas in functions.php, and then used dynamic_sidebar() to display the widgets in the template files.

Zac suggests using:

<?php

if ( ! is_active_sidebar( 'main-sidebar' ) ) {
	return;
}

?>

to prevent errors if no widgets are activated in main-sidebar. However, the only example he gives of how to use this is in the sidebar.php template file, where this and dynamic_sidebar() is the only code used in the whole file. If I try and use this in footer.php where there is a lot more code after dynamic_sidebar(), it prevents all the code from running. I’ve asked a question in the Udemy course to try and get an answer!

setting up menus

Alright! Today I registered a menu in functions.php using register_nav_menus(), and then told WP to display my menu by using wp_nav_menu() in header.php. I now have a menu on my site!

Also added the body_class() function to my HTML tag to make sure I have all those funky classes that come with it. And used the bloginfo() tag to pull in the site’s name and description.