Git Product home page Git Product logo

wds-block-based-theme's Introduction

WDS Block Based Theme

An experimental block based theme, which supports full site editing. Learn more about building Block Based Themes for WordPress.

Note: the following features are still experimental, and should not be used in a production environment.

WebDevStudios. Your Success is Our Mission.

Table of Contents


Requirements

  1. The Gutenberg Plugin must be installed and activated.
  2. Enable "Full Site Editing" under "Experiments":

screenshot


Theme Installation

Clone this repo into /wp-content/themes:

git clone [email protected]:WebDevStudios/wds-block-based-theme.git

Activate the theme:

screenshot


Glossary

Structure - Block based themes follow this structure:

theme
|__ style.css
|__ functions.php
|__ index.php
|__ experimental-theme.json
|__ block-templates
    |__ index.html
    |__ single.html
    |__ archive.html
    |__ ...
|__ block-template-parts
    |__ header.html
    |__ footer.html
    |__ sidebar.html
    |__ ...

Block & Block Grammar - An HTML comment containing information about a Block or Template Part. The following grammar creates a centered <p> tag in the block editor:

<!-- wp:paragraph {"align":"center"} -->
    <p>I am a centered paragraph tag</p>
<!-- /wp:paragraph -->

Template Parts - An HTML container for block grammar, which is displayed in Templates. To call a Template Part in a template, use this block grammar:

<!-- wp:template-part {"slug":"header","theme":"yourtheme"} /-->

Templates - An HTML container that displays Template Parts and Block Grammar. They follow the WordPress template hierarchy:

<!-- wp:template-part {"slug":"header","theme":"yourtheme"} /-->
<!-- wp:paragraph {"align":"center"} -->
    <p>I am a centered paragraph tag</p>
<!-- /wp:paragraph -->
<!-- wp:template-part {"slug":"footer","theme":"yourtheme"} /-->

Site Editor as Page Builder

Use the Site Editor to build your site:

screenshot

As you build, your Templates and Template Part block grammar are saved to the database, which can be accessed under the Appearance menu:

screenshot

You can even edit Templates and Template Parts individually from the Appearance menu:

screenshot


Export (Optional)

When you're finished building your site, you can export the your changes from the "Tools" menu:

screenshot

This action will export all of the Block Grammar into their respective Template and Template Part files. This feature is similar to ACF's Local JSON.

Place the exported Templates and Template Parts files into your theme:

screenshot

Everything you built in the Site Editor, is now available as code in your theme, which could be checked into version control or shipped to a client.

screenshot

If you look close, you'll see an additional postID paramenter in the Template Part grammar:

<!-- wp:template-part {"postID":94,"slug":"header","theme":"yourtheme"} /-->

This informs WordPress that the Header is also saved in the database, under postID: 94.


Global Styles via Theme JSON

Block based themes support an experimental-theme.json file. WordPress parses this file and makes these CSS variables available, without any need to write CSS. This feature feels similar to Theme UI.

The experimental-theme.json file:

  • Creates CSS variables (also called CSS custom properties) that can be used to style blocks both on the front and in the editor.
  • Sets global styles.
  • Sets styles for individual block types.

The following example would set a global CSS variable for all <h2> Blocks:

{
  "global": {
    "presets": {
      "color": [
        {
          "slug": "strong-magenta",
          "value": "#a156b4"
        }
      ]
    }
  },

  "core/heading/h2": {
    "styles": {
      "color": {
        "text": "var( --wp--preset--color--strong-magenta )"
      }
    }
  }
}

screenshot

Learn more about Theme JSON.


Theme Support

Block based themes will continue to leverage add_theme_support() as an "opt-in" way to extend and customize Core WordPress features.

The following features are:

  • align-wide
  • block-nav-menus
  • custom-line-height
  • custom-units
  • dark-editor-style
  • editor-color-palette
  • editor-gradient-presets
  • editor-font-sizes
  • experimental-custom-spacing
  • experimental-link-color
  • responsive-embeds
  • wp-block-styles

This example uses editor-color-palette to set default colors in the Block Editor:

function yourtheme_setup_theme_supported_features() {
    add_theme_support( 'editor-color-palette', array(
        array(
            'name'  => __( 'strong magenta', 'yourtheme' ),
            'slug'  => 'strong-magenta',
            'color' => '#a156b4',
        ),
        array(
            'name'  => __( 'very light gray', 'yourtheme' ),
            'slug'  => 'very-light-gray',
            'color' => '#f1f1f1',
        ),
    ) );
}
add_action( 'after_setup_theme', 'yourtheme_setup_theme_supported_features' );

This would be helpful if you needed to set your client's branding colors as defaults in the Block Editor:

screenshot

Learn more about available Theme Support options.


Learn more https://developer.wordpress.org/block-editor/tutorials/block-based-themes/

wds-block-based-theme's People

Contributors

gregrickaby avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.