RegionHalland / halland

Halland is a Wordpress theme by Region Halland ๐Ÿฒ
0 stars 2 forks source link
php wordpress wordpress-theme

Halland ๐Ÿฒ

Halland is a Wordpress theme built by Region Halland, based on Sage.

View theme structure

```shell themes/halland/ # โ†’ Root โ”œโ”€โ”€ app/ # โ†’ Theme PHP โ”‚ โ”œโ”€โ”€ Acf/ # โ†’ ACF Fields โ”‚ โ”œโ”€โ”€ controllers/ # โ†’ Controller files โ”‚ โ”œโ”€โ”€ Theme/ # โ†’ Enqueue files, register sidebars โ”‚ โ”œโ”€โ”€ Traits/ # โ†’ Traits used in the theme โ”‚ โ”œโ”€โ”€ admin.php # โ†’ Theme customizer setup โ”‚ โ”œโ”€โ”€ filters.php # โ†’ Theme filters โ”‚ โ”œโ”€โ”€ helpers.php # โ†’ Helper functions โ”‚ โ””โ”€โ”€ setup.php # โ†’ Theme setup โ”œโ”€โ”€ composer.json # โ†’ Autoloading for `app/` files โ”œโ”€โ”€ composer.lock # โ†’ Composer lock file (never edit) โ”œโ”€โ”€ dist/ # โ†’ Built theme assets (never edit) โ”œโ”€โ”€ node_modules/ # โ†’ Node.js packages (never edit) โ”œโ”€โ”€ package.json # โ†’ Node.js dependencies and scripts โ”œโ”€โ”€ resources/ # โ†’ Theme assets and templates โ”‚ โ”œโ”€โ”€ assets/ # โ†’ Front-end assets โ”‚ โ”‚ โ”œโ”€โ”€ config.json # โ†’ Settings for compiled assets โ”‚ โ”‚ โ”œโ”€โ”€ build/ # โ†’ Webpack and ESLint config โ”‚ โ”‚ โ”œโ”€โ”€ fonts/ # โ†’ Theme fonts โ”‚ โ”‚ โ”œโ”€โ”€ images/ # โ†’ Theme images โ”‚ โ”‚ โ”œโ”€โ”€ scripts/ # โ†’ Theme JS โ”‚ โ”‚ โ””โ”€โ”€ styles/ # โ†’ Theme stylesheets โ”‚ โ”œโ”€โ”€ functions.php # โ†’ Composer autoloader, theme includes โ”‚ โ”œโ”€โ”€ index.php # โ†’ Never manually edit โ”‚ โ”œโ”€โ”€ screenshot.png # โ†’ Theme screenshot for WP admin โ”‚ โ”œโ”€โ”€ style.css # โ†’ Theme meta information โ”‚ โ””โ”€โ”€ views/ # โ†’ Theme templates โ”‚ โ”œโ”€โ”€ layouts/ # โ†’ Base templates โ”‚ โ””โ”€โ”€ partials/ # โ†’ Partial templates โ””โ”€โ”€ vendor/ # โ†’ Composer packages (never edit) ```

Requirements

Getting started

  1. Clone Halland into the themes directory of your Wordpress installation and install dependencies:

    $ cd <your site>/web/app/themes/
    $ git clone https://github.com/RegionHalland/halland.git
    $ cd halland
    $ composer install && yarn
  2. Update resources/assets/config.json settings:

    • devUrl should reflect your local development hostname, for example http://site.test
    • publicPath should reflect your WordPress directory structure (/web/app/themes/halland or /wp-content/themes/halland for non-Bedrock installs)
  3. Build commands

    • yarn start โ€” Compile assets when file changes are made, start Browsersync session
    • yarn build โ€” Compile and optimize the files in your assets directory
    • yarn build:production โ€” Compile assets for production

Styleguide

Almost all of the CSS on the front-end is defined in our styleguide. Halland uses it by looking for the environment variable COMPONENT_LIBRARY_URI. If the variable can't be found, Halland defaults to the styleguide published on Github Pages.

If you want to work with CSS, set up up a local version of the styleguide by following the instructions in it's repo and make your changes there.

CORS

Allow requests to your local version of the styleguide by adding the following headers to it's nginx config:

  1. SSH into your Homestead server and edit the styleguides nginx config:

    $ cd ~/Homestead
    $ homestead ssh
    $ sudo nano /etc/nginx/sites-enabled/styleguide.test
  2. Place the headers in the server block of the nginx config:

    # Allow CORS
    add_header 'Access-Control-Allow-Origin' '*' always;
    add_header 'Access-Control-Allow-Credentials' 'true' always;
    add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
    add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
  3. Reload the nginx config.

    $ sudo service nginx reload

ACF Fields

Halland uses Advanced Custom Fields to create custom fields and ACF Export Manager to save the field definitions as .php and .json files, so that we can keep them under version control.

Importing

The field definitions are imported automatically with ACF Export Manager. The export manager will automatically import all field groups defined in /halland/Acf/Import.php.

To be imported, they must first be exported by following the instructions below. โคต๏ธ

Exporting

  1. Create your field group in the Wordpress admin panel like you normally would under Fields โ†’ Add new.

  2. Over the Save / Publish button to the right, you will find your field groups unique ID. It looks something like group_5b716c7b279da. Copy the field groups ID and add it to the array defined in /halland/Acf/Import.php:

    $acfExportManager->autoExport(array(
    ...
    ...
    'my-new-fieldgroup' => 'group_5b716c7b279da'
    ));
  3. Save / Publish your field group and ACF Export Manager will create a .php and a .json file for your new field group in each respective folder. Make sure to commit these files.

Editing existing field groups

  1. First of you need to identify the filename of the field group you want to edit. The easiest way to do this is probably to look at the key-value pairs found in the import array in /halland/Acf/Import.php.

  2. For minor changes you can edit the field groups directly in code. Remember to edit both the .json and the .php files found in /halland/Acf/<json or php>/my-new-field-group.<json or php>.

  3. For bigger changes you might want to use the admin panels interface. Go to Fields โ†’ Tools and import your field groups .json file (found in /halland/Acf/json/my-new-field-group.json).

  4. Edit your field group. When you Save / Publish, the changes will automatically be exported to code. Commit your changes! ๐Ÿค“

Child themes

TBD