forked from timber/starter-theme
-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.php
99 lines (77 loc) · 2.84 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?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;
}
Timber::$dirname = array('templates', 'views');
require_once(__DIR__ . '/lib/widgets/navbar_search.php');
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( '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_menus' ) );
add_shortcode( 'tease_post', array( $this, 'tease_post_func' ) );
add_action('wp_enqueue_scripts', array($this, 'scripts'));
add_action('widgets_init', array($this, 'widget_locations_init'));
add_action('widgets_init', function() {
register_widget('NavbarSearchWidget');
});
parent::__construct();
}
function tease_post_func($atts) {
$a = shortcode_atts(array( 'id' => false ), $atts);
$context = array(
'post' => new TimberPost($a['id']),
);
return Timber::compile('tease-post.twig', $context);
}
function scripts() {
wp_enqueue_script('jquery');
}
function widget_locations_init() {
register_sidebar(array(
'name' => 'Site Sidebar',
'id' => 'site_sidebar',
'before_widget' => '<div class="site-sidebar-widget">',
'after_widget' => '</div>',
'before_title' => '<div class="site-sidebar-widget-title">',
'after_title' => '</div>',
));
register_sidebar(array(
'name' => 'Site Nav',
'id' => 'site_nav_widgets',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
));
}
function register_post_types() { }
function register_taxonomies() { }
function register_menus() {
register_nav_menu('main-nav-bar', __('Main Navbar'));
}
function add_to_context( $context ) {
$context['site'] = $this;
$context['nav_bar'] = new TimberMenu('main-nav-bar');
$context['nav_widgets'] = Timber::get_widgets('site_nav_widgets');
$context['sidebar'] = Timber::get_widgets('site_sidebar');
return $context;
}
function add_to_twig( $twig ) {
$twig->addExtension( new Twig_Extension_StringLoader() );
$twig->addFunction( new Twig_SimpleFunction('columns', array($this, 'columns')));
return $twig;
}
function columns($n) {
return 12 / $n;
}
}
new StarterSite();