$ composer create-project themosis/themosis my-project-name
1 - Create the project
2 - Edit /config/environment.php
<?php
/*----------------------------------------------------*/
// Define environment type
/*----------------------------------------------------*/
return [
'local' => ['*.dev', 'scotchbox'],
'production' => 'themosis-101.com'
];
DB_NAME = "themosis101"
DB_USER = "root"
DB_PASSWORD = "root"
DB_HOST = "localhost"
WP_HOME = "http://themosis-101.dev"
WP_SITEURL = "http://themosis-101.dev/cms"
3 - Edit /.env.local
4 - Install and configure database
$ wp db create
Success: Database created.
$ wp core install --url=themosis-101.dev \
--title="Themosis 101" --admin_user=daniel \
--admin_password=verystrong \
--admin_email=daniel@ctrlweb.ca
Success: WordPress installed successfully.
+-- bootstrap/
+-- config/
| +-- environments/
| +-- environment.php
| +-- shared.php
+-- htdocs/
| +-- cms/
| +-- content/
| | +-- mu-plugins
| | +-- plugins
| | +-- themes/
| | +-- themosis-theme
| +-- index.php
| +-- wp-config.php
+-- library/
+-- storage/
+-- vendor/
+-- .env.local
+-- composer.json
+-- wp-cli.yml
+-- htdocs/
+-- content/
+-- themes/
+-- themosis-theme/
+-- assets/
+-- dist/
+-- languages/
+-- resources/
| +-- admin/
| +-- config/
| +-- controllers/
| +-- helpers/
| +-- models/
| +-- providers/
| +-- views/
| +-- widgets/
| +-- routes.php
+-- functions.php
+-- style.css
// WordPress "front" page
Route::get('front', 'Pages@home');
// WordPress page with defined template
Route::get('template', ['contact-template', 'uses' => 'Pages@contact']);
// Custom Post Type -- list and detail
Route::get('postTypeArchive', ['participant', 'uses' => 'Participants@all']);
Route::get('singular', ['participant', 'uses' => 'Participant@get']);
// 404 page
Route::get('404', 'Pages@page404');
// Specified URL with POST, or even other HTTP verbs!
Route::post('/participants/{$id}', 'Participants@get');
Route::delete('postTypeArchive', ['project', 'uses' => 'Projects@delete']);
Match an URL and a HTTP verb to a function (normally a Controller)
namespace Theme\Controllers;
use Themosis\Route\BaseController;
class Participants extends BaseController {
public function __construct() {
Asset::add('jquery', '//code.jquery.com/jquery-3.2.1.min.js', [], '3.2.1', true);
Asset::add('jquery-validation', themosis_theme_assets().'/js/jquery.validate.min.js',
['jquery'], '1.16.0', true);
Asset::add('themosis-101', 'css/themosis-101.css', false, '1.0', 'all');
}
public function all() {
return View::make('pages.participants', array('participants' => ParticipantsModel::all());
}
public function get($id) {
return View::make('pages.participant', array('participant' => ParticipantsModel::get($id));
}
}
Bridge between data and its visual representation. Orchestrates and delegates.
PostType::make('participant', __('Participants'), __('Participant'))->set([
'public' => true,
'rewrite' => [
'slug' => 'participants'
],
]);
Metabox::make('Details', 'participant')->set([
Field::media( 'picture', ['title' => __('Picture'), 'type' => 'image']),
Field::text( 'website', ['title' => __('Website'])),
]);
Create Custom Post Types and Fields in WordPress Admin.
class ParticipantModel {
public static function all($hydrate = true) {
$query = new WP_Query([
'post_type' => 'participant',
'posts_per_page' => -1,
'post_status' => 'publish'
]);
$participants = $query->get_posts();
if ($hydrate) {
$participants = self::hydrate($participants);
}
return $participants;
}
private static function hydrate($participants) {
foreach($participants as $participant) {
$participant->picture = Meta::get($participant->ID, 'picture');
$participant->website = Meta::get($participant->ID, 'website');
}
return $participants;
}
}
Retrieve data stored in the database.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Themosis 101</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="{{ themosis_theme_assets() }}/css/themosis-101.css">
<?php wp_head(); ?>
@yield('custom-styles')
</head>
<body>
<div class="container main-container">
@yield('main')
</div>
<footer class="footer">
@yield('footer')
</footer>
<?php wp_footer(); ?>
</body>
</html>
Represent data in a certain format (typically HTML)
@extends('layouts.page')
@section('main')
<h1>Participants</h1>
@foreach($participants as $participant)
{{ $participant->website }}
@endforeach
@endsection
@section('footer')
© Copyright 2017 - ctrlweb
@endsection