Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@

$context['title'] = 'Archive';
if ( is_day() ) {
$context['title'] = 'Archive: '.get_the_date( 'D M Y' );
$context['title'] = 'Archive: '.get_the_date( 'D M Y' );
} else if ( is_month() ) {
$context['title'] = 'Archive: '.get_the_date( 'M Y' );
$context['title'] = 'Archive: '.get_the_date( 'M Y' );
} else if ( is_year() ) {
$context['title'] = 'Archive: '.get_the_date( 'Y' );
$context['title'] = 'Archive: '.get_the_date( 'Y' );
} else if ( is_tag() ) {
$context['title'] = single_tag_title( '', false );
$context['title'] = single_tag_title( '', false );
} else if ( is_category() ) {
$context['title'] = single_cat_title( '', false );
array_unshift( $templates, 'archive-' . get_query_var( 'cat' ) . '.twig' );
$context['title'] = single_cat_title( '', false );
array_unshift( $templates, 'archive-' . get_query_var( 'cat' ) . '.twig' );
} else if ( is_post_type_archive() ) {
$context['title'] = post_type_archive_title( '', false );
array_unshift( $templates, 'archive-' . get_post_type() . '.twig' );
$context['title'] = post_type_archive_title( '', false );
array_unshift( $templates, 'archive-' . get_post_type() . '.twig' );
}

$context['posts'] = Timber::get_posts();
Expand Down
6 changes: 3 additions & 3 deletions author.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
$context = Timber::get_context();
$context['posts'] = Timber::get_posts();
if ( isset( $wp_query->query_vars['author'] ) ) {
$author = new TimberUser( $wp_query->query_vars['author'] );
$context['author'] = $author;
$context['title'] = 'Author Archives: ' . $author->name();
$author = new TimberUser( $wp_query->query_vars['author'] );
$context['author'] = $author;
$context['title'] = 'Author Archives: ' . $author->name();
}
Timber::render( array( 'author.twig', 'archive.twig' ), $context );
2 changes: 1 addition & 1 deletion footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

$timberContext = $GLOBALS['timberContext'];
if ( ! isset( $timberContext ) ) {
throw new \Exception( 'Timber context not set in footer.' );
throw new \Exception( 'Timber context not set in footer.' );
}
$timberContext['content'] = ob_get_contents();
ob_end_clean();
Expand Down
165 changes: 85 additions & 80 deletions functions.php
Original file line number Diff line number Diff line change
@@ -1,92 +1,97 @@
<?php

if ( ! class_exists( 'Timber' ) ) {
add_action( 'admin_notices', function() {
echo '<div class="error"><p>Timber not activated. Make sure you activate the plugin in <a href="' . esc_url( admin_url( 'plugins.php#timber' ) ) . '">' . esc_url( admin_url( 'plugins.php' ) ) . '</a></p></div>';
} );
return;
add_action( 'admin_notices', function() {
echo '<div class="error"><p>Timber not activated. Make sure you activate the plugin in <a href="' . esc_url( admin_url( 'plugins.php#timber' ) ) . '">' . esc_url( admin_url( 'plugins.php' ) ) . '</a></p></div>';
} );
return;
}

Timber::$dirname = array('templates', 'views');

class StarterSite extends TimberSite {

function __construct() {
add_theme_support( 'post-formats' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'menus' );
add_filter( 'timber_context', array( $this, 'add_to_context' ) );
add_filter( 'comment_form_default_fields', array( $this, 'bootstrap3_comment_form_fields' ) );
add_filter( 'comment_form_defaults', array( $this, 'bootstrap3_comment_form' ) );
add_filter( 'get_twig', array( $this, 'add_to_twig' ) );
add_action( 'init', array( $this, 'register_post_types' ) );
add_action( 'init', array( $this, 'register_taxonomies' ) );
add_action( 'init', array( $this, 'register_my_menu' ) );
parent::__construct();
}

function register_my_menu() {
register_nav_menu('main-menu', __( 'Main Menu' ));
}

function bootstrap3_comment_form_fields( $fields ) {
$commenter = wp_get_current_commenter();

$req = get_option( 'require_name_email' );
$aria_req = ( $req ? " aria-required='true'" : '' );
$html5 = current_theme_supports( 'html5', 'comment-form' ) ? 1 : 0;

$fields = array(
'author' => '<div class="form-group comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
'<input class="form-control" id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></div>',
'email' => '<div class="form-group comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
'<input class="form-control" id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></div>',
'url' => '<div class="form-group comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' .
'<input class="form-control" id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></div>'
);

return $fields;
}

function bootstrap3_comment_form( $args ) {
$args['comment_field'] = '<div class="form-group comment-form-comment">
<label for="comment">' . _x( 'Comment', 'noun' ) . '</label>
<textarea class="form-control" id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea>
</div>';
$args['class_submit'] = 'btn btn-default'; // since WP 4.1

return $args;
}

function register_post_types() {
//this is where you can register custom post types
}

function register_taxonomies() {
//this is where you can register custom taxonomies
}

function add_to_context( $context ) {
$context['menu'] = new TimberMenu('main-menu');
$context['site'] = $this;

$context['posts'] = Timber::get_posts();
$context['pagination'] = Timber::get_pagination();
$context['categories'] = Timber::get_terms('category');
return $context;
}

function myfoo( $text ) {
$text .= ' bar!';
return $text;
}

function add_to_twig( $twig ) {
/* this is where you can add your own fuctions to twig */
$twig->addExtension( new Twig_Extension_StringLoader() );
$twig->addFilter('myfoo', new Twig_SimpleFilter('myfoo', array($this, 'myfoo')));
return $twig;
}
function __construct() {
add_theme_support( 'post-formats' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'menus' );
add_filter( 'timber_context', array( $this, 'add_to_context' ) );
add_filter( 'comment_form_default_fields', array( $this, 'bootstrap3_comment_form_fields' ) );
add_filter( 'comment_form_defaults', array( $this, 'bootstrap3_comment_form' ) );
add_filter( 'get_twig', array( $this, 'add_to_twig' ) );
add_action( 'init', array( $this, 'register_post_types' ) );
add_action( 'init', array( $this, 'register_taxonomies' ) );
add_action( 'init', array( $this, 'register_my_menu' ) );
parent::__construct();
}

function register_my_menu() {
register_nav_menu('main-menu', __( 'Main Menu' ));
}

function bootstrap3_comment_form_fields( $fields ) {
$commenter = wp_get_current_commenter();

$req = get_option( 'require_name_email' );
$aria_req = ( $req ? " aria-required='true'" : '' );
$html5 = current_theme_supports( 'html5', 'comment-form' ) ? 1 : 0;

$fields = array(
'author' => '<div class="form-group comment-form-author">
<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label>
<input class="form-control" id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' />
</div>',
'email' => '<div class="form-group comment-form-email">
<label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label>
<input class="form-control" id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' />
</div>',
'url' => '<div class="form-group comment-form-url">
<label for="url">' . __( 'Website' ) . '</label>
<input class="form-control" id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" />
</div>'
);

return $fields;
}

function bootstrap3_comment_form( $args ) {
$args['comment_field'] = '<div class="form-group comment-form-comment">
<label for="comment">' . _x( 'Comment', 'noun' ) . '</label>
<textarea class="form-control" id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea>
</div>';
$args['class_submit'] = 'btn btn-default'; // since WP 4.1
return $args;
}

function register_post_types() {
//this is where you can register custom post types
}

function register_taxonomies() {
//this is where you can register custom taxonomies
}

function add_to_context( $context ) {
$context['menu'] = new TimberMenu('main-menu');
$context['site'] = $this;

$context['posts'] = Timber::get_posts();
$context['pagination'] = Timber::get_pagination();
$context['categories'] = Timber::get_terms('category');
return $context;
}

function myfoo( $text ) {
$text .= ' bar!';
return $text;
}

function add_to_twig( $twig ) {
/* this is where you can add your own fuctions to twig */
$twig->addExtension( new Twig_Extension_StringLoader() );
$twig->addFilter('myfoo', new Twig_SimpleFilter('myfoo', array($this, 'myfoo')));
return $twig;
}

}

Expand Down
2 changes: 1 addition & 1 deletion header.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Third party plugins that hijack the theme will call wp_head() to get the header template.
* We use this to start our output buffer and render into the view/page-plugin.twig template in footer.php
*
* If you're not using a plugin that requries this behavior (ones that do include Events Calendar Pro and
* If you're not using a plugin that requries this behavior (ones that do include Events Calendar Pro and
* WooCommerce) you can delete this file and footer.php
*/

Expand Down
6 changes: 3 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
*/

if ( ! class_exists( 'Timber' ) ) {
echo 'Timber not activated. Make sure you activate the plugin in <a href="/wp-admin/plugins.php#timber">/wp-admin/plugins.php</a>';
return;
echo 'Timber not activated. Make sure you activate the plugin in <a href="/wp-admin/plugins.php#timber">/wp-admin/plugins.php</a>';
return;
}

$context = Timber::get_context();
$context['posts'] = Timber::get_posts();

$templates = array( 'index.twig' );
if ( is_home() ) {
array_unshift( $templates, 'home.twig' );
array_unshift( $templates, 'home.twig' );
}
Timber::render( $templates, $context );
6 changes: 2 additions & 4 deletions mkzip.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#!/bin/bash

rm -f cd-theme.zip
rm -rf cd-theme/
DIRS_TO_COPY=`ls | tr "\n" " "`
rm -f cd-theme.zip cd-theme/
mkdir cd-theme
cp -r $DIRS_TO_COPY cd-theme/
cp -r ./* cd-theme/
rm -rf cd-theme/.git/
zip -r cd-theme.zip cd-theme/
rm -rf cd-theme/
1 change: 0 additions & 1 deletion page-about.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


$context = Timber::get_context();
$post = new TimberPost();
$context['post'] = $post;
Expand Down
Loading