summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--Readme.md8
-rw-r--r--app/Site.php87
-rw-r--r--composer.json22
-rw-r--r--footer.php5
-rw-r--r--functions.php5
-rw-r--r--header.php4
-rw-r--r--index.php8
-rw-r--r--package.json11
-rw-r--r--resources/css/index.scss4
-rw-r--r--resources/js/index.js1
-rw-r--r--resources/views/base.twig21
-rw-r--r--resources/views/components/menu-item.twig10
-rw-r--r--resources/views/index.twig8
-rw-r--r--resources/views/root.twig17
-rw-r--r--style.css10
-rw-r--r--webpack.config.js12
17 files changed, 236 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..451f104
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+/vendor
+/node_modules
+/build
diff --git a/Readme.md b/Readme.md
new file mode 100644
index 0000000..790c8a5
--- /dev/null
+++ b/Readme.md
@@ -0,0 +1,8 @@
+## Instructions
+
+```
+composer create-project dweipert/wp-theme-boilerplate yourthemename
+cd yourthemename
+npm i
+npm start
+```
diff --git a/app/Site.php b/app/Site.php
new file mode 100644
index 0000000..5e45535
--- /dev/null
+++ b/app/Site.php
@@ -0,0 +1,87 @@
+<?php
+
+namespace Theme;
+
+use Dweipert\WpEnqueueAssets\UsesWordPressScripts;
+use Timber\Menu;
+use Timber\Timber;
+use Twig\Environment;
+use Twig\Extension\StringLoaderExtension;
+use Twig\TwigFunction;
+
+class Site extends \Timber\Site
+{
+ use UsesWordPressScripts;
+
+ /**
+ * Site constructor.
+ */
+ public function __construct()
+ {
+ add_action('after_setup_theme', [$this, 'themeSupports']);
+ add_action('wp_enqueue_scripts', [$this, 'enqueueScripts']);
+ add_filter('timber/context', [$this, 'addToContext']);
+ add_filter('timber/twig', [$this, 'addToTwig']);
+
+ Timber::$dirname = 'resources/views';
+
+ parent::__construct();
+ }
+
+ /**
+ * Add Theme supports
+ * after_setup_theme callback
+ */
+ public function themeSupports()
+ {
+ add_theme_support('title-tag');
+ add_theme_support('post-thumbnails');
+ add_theme_support('html5');
+
+ // menu
+ add_theme_support('menus');
+ register_nav_menus([
+ 'main' => 'Main',
+ 'footer' => 'Footer',
+ ]);
+ }
+
+ /**
+ * wp_enqueue_scripts callback
+ */
+ public function enqueueScripts()
+ {
+ $this->enqueueStyle('theme', 'index.css');
+ $this->enqueueScript('theme', 'index.js', ['jquery'], true);
+ }
+
+ /**
+ * @param array $context
+ *
+ * @return mixed
+ */
+ public function addToContext($context)
+ {
+ $context['site'] = $this;
+
+ $context['menu'] = [];
+ foreach (get_registered_nav_menus() as $location => $name) {
+ $context['menu'][$location] = new Menu($location);
+ }
+
+ return $context;
+ }
+
+ /**
+ * @param Environment $twig
+ *
+ * @return Environment
+ */
+ public function addToTwig(Environment $twig)
+ {
+ $twig->addExtension(new StringLoaderExtension());
+ $twig->addFunction(new TwigFunction('assets_url', [$this, 'assetsUrl']));
+
+ return $twig;
+ }
+}
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..9f68717
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,22 @@
+{
+ "name": "dweipert/wp-theme-boilerplate",
+ "type": "wordpress-theme",
+ "description": "WordPress Theme Boilerplate",
+ "license": "GPL-2.0-or-later",
+ "authors": [
+ {
+ "name": "Daniel Weipert",
+ "email": "code@drogueronin.de"
+ }
+ ],
+ "require": {
+ "php": ">=7.4",
+ "dweipert/wp-enqueue-assets": "^1.0",
+ "timber/timber": "^1.18"
+ },
+ "autoload": {
+ "psr-4": {
+ "Theme\\": "app/"
+ }
+ }
+}
diff --git a/footer.php b/footer.php
new file mode 100644
index 0000000..aab3545
--- /dev/null
+++ b/footer.php
@@ -0,0 +1,5 @@
+<?php
+
+$timberContext = $GLOBALS['timberContext'];
+$timberContext['content'] = ob_get_contents();
+ob_end_clean();
diff --git a/functions.php b/functions.php
new file mode 100644
index 0000000..a50eb09
--- /dev/null
+++ b/functions.php
@@ -0,0 +1,5 @@
+<?php
+
+require_once __DIR__ . '/vendor/autoload.php';
+
+new \Theme\Site();
diff --git a/header.php b/header.php
new file mode 100644
index 0000000..4631a08
--- /dev/null
+++ b/header.php
@@ -0,0 +1,4 @@
+<?php
+
+$GLOBALS['timberContext'] = \Timber\Timber::context();
+ob_start();
diff --git a/index.php b/index.php
new file mode 100644
index 0000000..38c8671
--- /dev/null
+++ b/index.php
@@ -0,0 +1,8 @@
+<?php
+
+$context = \Timber\Timber::context();
+$templates = ['index.twig'];
+
+$context['posts'] = new \Timber\PostQuery();
+
+\Timber\Timber::render($templates, $context);
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..b848e30
--- /dev/null
+++ b/package.json
@@ -0,0 +1,11 @@
+{
+ "name": "@dweipert/wp-theme-boilerplate",
+ "scripts": {
+ "start": "wp-scripts start",
+ "build": "wp-scripts build"
+ },
+ "dependencies": {},
+ "devDependencies": {
+ "@wordpress/scripts": "^13.0.3"
+ }
+}
diff --git a/resources/css/index.scss b/resources/css/index.scss
new file mode 100644
index 0000000..b441eae
--- /dev/null
+++ b/resources/css/index.scss
@@ -0,0 +1,4 @@
+html, body {
+ padding: 0;
+ margin: 0;
+}
diff --git a/resources/js/index.js b/resources/js/index.js
new file mode 100644
index 0000000..33ddd72
--- /dev/null
+++ b/resources/js/index.js
@@ -0,0 +1 @@
+console.log('index');
diff --git a/resources/views/base.twig b/resources/views/base.twig
new file mode 100644
index 0000000..c42770a
--- /dev/null
+++ b/resources/views/base.twig
@@ -0,0 +1,21 @@
+{% extends 'root.twig' %}
+
+{% block body %}
+ <header class="header">
+ {% block header %}
+ <nav>
+ <ul>
+ {% for item in menu.main.items %}
+ {% include 'components/menu-item.twig' with { 'item': item } %}
+ {% endfor %}
+ </ul>
+ </nav>
+ {% endblock %}
+ </header>
+ <main>
+ {% block main %}{% endblock %}
+ </main>
+ <footer>
+ {% block footer %}{% endblock %}
+ </footer>
+{% endblock %}
diff --git a/resources/views/components/menu-item.twig b/resources/views/components/menu-item.twig
new file mode 100644
index 0000000..5bc41fc
--- /dev/null
+++ b/resources/views/components/menu-item.twig
@@ -0,0 +1,10 @@
+<li class="{{ (item.classes | merge(item._menu_item_classes)) | join(' ') }}">
+ <a target="{{ item.target }}" href="{{ item.link }}">{{ item.title }}</a>
+ {% if current_depth < depth and item.children %}
+ <ul>
+ {% for child in item.children %}
+ {% include 'components/menu-item.twig' with { 'item': child, 'depth': depth, 'current_depth': current_depth + 1 } %}
+ {% endfor %}
+ </ul>
+ {% endif %}
+</li>
diff --git a/resources/views/index.twig b/resources/views/index.twig
new file mode 100644
index 0000000..48b345c
--- /dev/null
+++ b/resources/views/index.twig
@@ -0,0 +1,8 @@
+{% extends 'base.twig' %}
+
+{% block main %}
+ {% for post in posts %}
+ <h1>{{ post.title }}</h1>
+ <p>{{ post.content }}</p>
+ {% endfor %}
+{% endblock %}
diff --git a/resources/views/root.twig b/resources/views/root.twig
new file mode 100644
index 0000000..3075eba
--- /dev/null
+++ b/resources/views/root.twig
@@ -0,0 +1,17 @@
+<html {{ site.language_attributes }}>
+<head>
+ <meta charset="{{ site.charset }}" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+ <meta name="description" content="{{ site.description }}">
+ {% block meta %}{% endblock %}
+ {{ function('wp_head') }}
+ {% block css %}{% endblock %}
+</head>
+<body class="{{ body_class }}">
+{% block body %}{% endblock %}
+{{ function('wp_footer') }}
+{% block js %}{% endblock %}
+</body>
+</html>
diff --git a/style.css b/style.css
new file mode 100644
index 0000000..c9ffac5
--- /dev/null
+++ b/style.css
@@ -0,0 +1,10 @@
+/*
+Theme Name: WP Theme Boilerplate
+Text Domain: textdomain
+Version: 1.0.0
+Author: dweipert
+Author URI: https://dweipert.de
+Theme URI: https://gitlab.com/dweipert.de/wordpress/wp-theme-boilerplate
+License: GNU General Public License v2 or later
+License URI: http://www.gnu.org/licenses/gpl-2.0.html
+*/
diff --git a/webpack.config.js b/webpack.config.js
new file mode 100644
index 0000000..61ed3f6
--- /dev/null
+++ b/webpack.config.js
@@ -0,0 +1,12 @@
+const defaultConfig = require('@wordpress/scripts/config/webpack.config');
+
+module.exports = {
+ ...defaultConfig,
+
+ entry: {
+ index: [
+ './resources/js/index.js',
+ './resources/css/index.scss',
+ ],
+ },
+};