WordPress Day 8 - Underscores 1 What is underscores? _s, or - - PowerPoint PPT Presentation

wordpress
SMART_READER_LITE
LIVE PREVIEW

WordPress Day 8 - Underscores 1 What is underscores? _s, or - - PowerPoint PPT Presentation

TWD 25 WordPress Day 8 - Underscores 1 What is underscores? _s, or underscores , is a WordPress starter theme. It is a code base for building custom themes. 2 Why use underscores? Maintained by Automattic developers. This is the


slide-1
SLIDE 1

TWD 25

WordPress

Day 8 - Underscores

1

slide-2
SLIDE 2

2

What is underscores?

_s, or underscores, is a WordPress starter theme. It is a code base for building custom themes.

slide-3
SLIDE 3

3

Why use underscores?

Maintained by Automattic developers. This is the recommended starter theme for both WordPress.org and WordPress.com. Regularly updated and kept up to the standards.

slide-4
SLIDE 4

4

WordPress Custom Themes

You don’t build custom themes from scratch… …you build your theme on a solid foundation.

slide-5
SLIDE 5

5

How do you start?

Visit underscores.me Add a name for your theme and this will replace all the _s namespace prefixes and create a theme for you.

slide-6
SLIDE 6

6

Advanced Options

Click “Advanced Options”. Apart from the Theme Slug, these fields can be changed in style.css later.

slide-7
SLIDE 7

7

Pick a Unique Theme Slug

Before selecting a Theme Slug, search for it on https://wordpress.org/themes/ If it already exists… you will get update notifications in WordPress that aren’t for your theme!

slide-8
SLIDE 8

8

Advanced Options - Example

Type in your theme name. Type in your unique theme slug... lowercase with no spaces.

slide-9
SLIDE 9

9

Advanced Options

Check the box if your theme will support WooCommerce. Check the box to include the Sass files in your theme.

slide-10
SLIDE 10

10

Activate your starter theme

Click “Generate” to download your zipped theme folder. Extract the theme and add it to your wp-content/themes folder or use the Upload theme

  • ption in WordPress.

Activate the theme.

slide-11
SLIDE 11

11

Start developing!

You now have your own version of the underscores starter theme that you can edit to create a custom theme.

slide-12
SLIDE 12

12

Exercise: Create a starter theme

Follow the steps from the previous slides to create your own starter theme. Install and activate the starter theme on your local Vancouver website.

slide-13
SLIDE 13

13

Lacks most styling

At first glance, it looks bad. There is no styling other than the basic structure. But the code foundation is solid.

slide-14
SLIDE 14

14

style.css - Theme Details

You can update the theme information in the style.css header comment.

slide-15
SLIDE 15

15

style.css - Table of Contents

Use the table of contents to find where to edit or add CSS. Remember… the structure and order matters.

slide-16
SLIDE 16

16

style.css - Comparing to TWD Theme

The twd-starter-theme used for the Mindset site is a variation of Underscores that has more styles. Underscores does not include any Layout, Header1 or Footer sections. You would create those yourself.

1 There are default styles for the header navigation menu though.

slide-17
SLIDE 17

17

File Structure

The file structure is well thought out and allows for easy customization and DRY development practices.

slide-18
SLIDE 18

18

Development Files and Folders

The following files and folders are specifically for your development environment. WordPress does not use these so you can remove them or ignore them if you are not using them: bin folder composer.json .eslintrc package.json .stylelintrc.json phpcs.xml.dist

slide-19
SLIDE 19

19

Folder Structure

inc → PHP files to be required into functions.php. js → JavaScript files to be enqueued in functions.php. languages → Translation files. sass → Sass files to be compiled into style.css. template-parts → PHP template part files.

slide-20
SLIDE 20

20

Use the Template Hierarchy

Use the Template Hierarchy chart to see what files need to be edited or created.

slide-21
SLIDE 21

21

Page

The page template displays page content as well as comments, if enabled.

content-page.php comments.php

Page page.php

slide-22
SLIDE 22

22

Single Post

The single post template displays post content as well as comments.

content.php comments.php

Single post single.php

slide-23
SLIDE 23

23

The Blog Index

By default the “Posts” index is typically the landing page for WordPress sites.

content.php content-none.php

Blog index index.php

slide-24
SLIDE 24

24

Archives

By default, all archives (lists of posts) except the Blog index are handled by archive.php.

content-[post-type].php content-none.php Archives: Category Tag Author Day / Month / Year Custom Post Type Index Taxonomy Term Index

archive.php

slide-25
SLIDE 25

25

Search Results

Search Results are displayed in a default loop using their own search.php template.

content-search.php content-none.php

Search results search.php

slide-26
SLIDE 26

Semantic Structure

#page .site #masthead .site-header #colophon .site-footer #primary .site-main #secondary .widget-area (Optional)

Main semantic structure. It is featured

  • n all template

pages in the theme. Each element has an ID and minimum one class.

26

slide-27
SLIDE 27

Semantic Structure: #masthead

<header> #masthead .site-header <div> .site-branding

header.php

<h1> .site-title <p> .site-description <nav> #site-navigation .main-navigation <button> .menu-toggle (for mobile screen) <div> .menu <ul> .nav-menu

27

slide-28
SLIDE 28

<main> #primary .content-area

Semantic Structure: #primary

Base template files:

index.php, single.php, archive.php, etc. + content.php, content-page.php, etc.

<article> #post-[ID] .[post-classes] <nav> .navigation .post-navigation <div> #comments .comments-area

<header> .entry-header

  • title + post meta (date, author)

<div> .entry-content

  • content / excerpt + post paging navigation

<footer> .entry-footer

  • post meta (categories, tags, edit link)

28

slide-29
SLIDE 29

Semantic Structure: #secondary

<aside> #secondary .widget-area <section> #[widget-name-ID] .widget .[widget-type]

sidebar.php

<h2> .widget-title <ul> <section> #[widget-name-ID] .widget .[widget-type] <h2> .widget-title <ul>

29

slide-30
SLIDE 30

30

How to start development

Check functions.php and see what the starter theme supports by default. Examples: Featured Images, Custom Background, Custom Logo. These can be deactivated by deleting the code if you don’t want the feature in your theme.

slide-31
SLIDE 31

Set the default content width in the functions.php. This value controls the max width in pixels of media elements like oEmbeds and Images.

31

Set the content width

slide-32
SLIDE 32

32

Custom header

Underscores has a feature for a custom header… …but you need to add some code where you want to display the custom header…

slide-33
SLIDE 33

33

Custom header

Place the sample code from /inc/custom-header.php into header.php or wherever you wish to display the header image.

slide-34
SLIDE 34

34

Block Editor Support

Underscores currently doesn’t include code to fully support the block editor. Use add_theme_support() to opt-in to the features you wish to support, then update your CSS accordingly.

https://developer.wordpress.org/block-editor/developers/themes/theme-support/

slide-35
SLIDE 35

35

Block Editor Opt-in Examples

add_theme_support( 'wp-block-styles' ) add_theme_support( 'responsive-embeds' ) add_theme_support( 'align-wide' ) add_theme_support( 'custom-line-height' ) add_theme_support( 'custom-units' )

You can also change the color palettes and font sizes

  • r disable those options too.
slide-36
SLIDE 36

36

Block Editor Styles

To add front end styles to the back end block editor use the following functions: add_theme_support( 'editor-styles' ) add_editor_style( 'style-editor.css' )

slide-37
SLIDE 37

37

Block Editor Resources

LinkedIn Learning Tutorial: WordPress Content Blocks: Working with Themes Official Documentation: Block Editor Handbook: Theme Support

slide-38
SLIDE 38

38

get_template_part()

Underscores uses the fallback feature of get_template_part() to limit the number of files you need to create. Open index.php, archive.php, or single.php to see:

slide-39
SLIDE 39

39

get_template_part()

If we had a post type named ms-work, the previous code would look for content-ms-work.php in the template-parts folder. If that file did not exist, that code would fallback to using content.php.

slide-40
SLIDE 40

40

Styling

Write your CSS mobile-first. Use media queries for larger screen sizes. Put your general styles in the first few sections of style.css: Typography, Elements, Forms, etc. Put your page specific styles using the body class in the Content section.

slide-41
SLIDE 41

41

Styling - Where to begin

Start by styling the header and footer to create the framework for your content. Then set the generic styles for your site and its content. Then move on to styling specific pages and sections.

slide-42
SLIDE 42

42

Styling - Single then Archive

Style the single blog post template and any single custom post types first. These same styles can then apply to the archive pages as well and only minor changes need to be made.

slide-43
SLIDE 43

43

Single post Index/Archive

slide-44
SLIDE 44

44

Styling - Pages

Your general styles should apply to Pages and then page specific styles can be added in the Content section of style.css. If your home page reuses content from throughout the site, style it last to reuse the already created styles.

slide-45
SLIDE 45

45

Styling - Search & 404

Don’t forget to style 404 page and change its content in 404.php. Don’t forget to style the search results page for when it finds results and when it does not find results.

slide-46
SLIDE 46

46

Sass in underscores

If you checked the _sassify! checkbox when creating the theme... underscores creates the necessary Sass partials and has them organized into subfolders in the sass folder. Note: We will cover Sass in underscores during the Capstone Project, use regular CSS for now.

slide-47
SLIDE 47

47

Underscores Tutorial

LinkedIn Learning:

https://www.linkedin.com/learning/wordpress-building-themes-from-scratch-using-underscores-2/

Note: Some aspects of the tutorials may be out of date for the current version of Underscores.