Add theme wrapper, re-organize template files
- Implement scribu’s Theme Wrapper (see base.php) - Move templates, comments.php, and searchform.php to templates/ folder - Rename loop- files to content- - Remove all hooks except roots_head and roots_footer - Use templates/page-header.php for page titles - Use head.php for everything in <head>
This commit is contained in:
@@ -435,11 +435,7 @@ class Roots_Nav_Walker extends Walker_Nav_Menu {
|
||||
}
|
||||
|
||||
function start_lvl(&$output, $depth) {
|
||||
if (current_theme_supports('bootstrap-top-navbar')) {
|
||||
$output .= "\n<ul class=\"dropdown-menu\">\n";
|
||||
} else {
|
||||
$output .= "\n<ul class=\"sub-menu\">\n";
|
||||
}
|
||||
$output .= "\n<ul class=\"dropdown-menu\">\n";
|
||||
}
|
||||
|
||||
function start_el(&$output, $item, $depth, $args) {
|
||||
@@ -455,11 +451,9 @@ class Roots_Nav_Walker extends Walker_Nav_Menu {
|
||||
|
||||
$classes = array_filter($classes, array(&$this, 'check_current'));
|
||||
|
||||
if (current_theme_supports('bootstrap-top-navbar')) {
|
||||
if ($args->has_children) {
|
||||
$classes[] = 'dropdown';
|
||||
$li_attributes .= ' data-dropdown="dropdown"';
|
||||
}
|
||||
if ($args->has_children) {
|
||||
$classes[] = 'dropdown';
|
||||
$li_attributes .= ' data-dropdown="dropdown"';
|
||||
}
|
||||
|
||||
if ($custom_classes = get_post_meta($item->ID, '_menu_item_classes', true)) {
|
||||
@@ -477,16 +471,12 @@ class Roots_Nav_Walker extends Walker_Nav_Menu {
|
||||
$attributes .= ! empty($item->target) ? ' target="' . esc_attr($item->target ) .'"' : '';
|
||||
$attributes .= ! empty($item->xfn) ? ' rel="' . esc_attr($item->xfn ) .'"' : '';
|
||||
$attributes .= ! empty($item->url) ? ' href="' . esc_attr($item->url ) .'"' : '';
|
||||
if (current_theme_supports('bootstrap-top-navbar')) {
|
||||
$attributes .= ($args->has_children) ? ' class="dropdown-toggle" data-toggle="dropdown"' : '';
|
||||
}
|
||||
$attributes .= ($args->has_children) ? ' class="dropdown-toggle" data-toggle="dropdown"' : '';
|
||||
|
||||
$item_output = $args->before;
|
||||
$item_output .= '<a'. $attributes .'>';
|
||||
$item_output .= $args->link_before . apply_filters('the_title', $item->title, $item->ID) . $args->link_after;
|
||||
if (current_theme_supports('bootstrap-top-navbar')) {
|
||||
$item_output .= ($args->has_children) ? ' <b class="caret"></b>' : '';
|
||||
}
|
||||
$item_output .= ($args->has_children) ? ' <b class="caret"></b>' : '';
|
||||
$item_output .= '</a>';
|
||||
$item_output .= $args->after;
|
||||
|
||||
@@ -531,8 +521,6 @@ class Roots_Nav_Walker extends Walker_Nav_Menu {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Cleanup wp_nav_menu_args
|
||||
*
|
||||
@@ -677,3 +665,12 @@ function roots_embed_wrap($cache, $url, $attr = '', $post_ID = '') {
|
||||
|
||||
add_filter('embed_oembed_html', 'roots_embed_wrap', 10, 4);
|
||||
add_filter('embed_googlevideo', 'roots_embed_wrap', 10, 2);
|
||||
|
||||
/**
|
||||
* Tell WordPress to use searchform.php from the templates/ directory
|
||||
*/
|
||||
function roots_get_search_form() {
|
||||
locate_template('/templates/searchform.php', true, true);
|
||||
}
|
||||
|
||||
add_filter('get_search_form', 'roots_get_search_form');
|
||||
|
||||
@@ -2,27 +2,42 @@
|
||||
/**
|
||||
* Roots configuration and constants
|
||||
*/
|
||||
|
||||
add_theme_support('root-relative-urls'); // Enable relative URLs
|
||||
add_theme_support('rewrite-urls'); // Enable URL rewrites
|
||||
add_theme_support('h5bp-htaccess'); // Enable HTML5 Boilerplate's .htaccess
|
||||
add_theme_support('bootstrap-responsive'); // Enable Bootstrap's responsive CSS
|
||||
add_theme_support('bootstrap-top-navbar'); // Enable Bootstrap's fixed navbar
|
||||
|
||||
// Set the content width based on the theme's design and stylesheet
|
||||
if (!isset($content_width)) { $content_width = 940; }
|
||||
// Define which pages shouldn't have the sidebar
|
||||
function roots_sidebar() {
|
||||
if (is_404() || is_page_template('page-custom.php')) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// #main CSS classes
|
||||
function roots_main_class() {
|
||||
if (roots_sidebar()) {
|
||||
echo 'span8';
|
||||
} else {
|
||||
echo 'span12';
|
||||
}
|
||||
}
|
||||
|
||||
// #sidebar CSS classes
|
||||
function roots_sidebar_class() {
|
||||
echo 'span4';
|
||||
}
|
||||
|
||||
define('GOOGLE_ANALYTICS_ID', ''); // UA-XXXXX-Y
|
||||
define('POST_EXCERPT_LENGTH', 40);
|
||||
define('WRAP_CLASSES', 'container');
|
||||
define('CONTAINER_CLASSES', 'row');
|
||||
define('MAIN_CLASSES', 'span8');
|
||||
define('SIDEBAR_CLASSES', 'span4');
|
||||
define('FULLWIDTH_CLASSES', 'span12');
|
||||
define('GOOGLE_ANALYTICS_ID', ''); // UA-XXXXX-Y
|
||||
|
||||
define('WP_BASE', wp_base_dir());
|
||||
define('THEME_NAME', next(explode('/themes/', get_template_directory())));
|
||||
define('RELATIVE_PLUGIN_PATH', str_replace(site_url() . '/', '', plugins_url()));
|
||||
define('FULL_RELATIVE_PLUGIN_PATH', WP_BASE . '/' . RELATIVE_PLUGIN_PATH);
|
||||
define('RELATIVE_CONTENT_PATH', str_replace(site_url() . '/', '', content_url()));
|
||||
define('THEME_PATH', RELATIVE_CONTENT_PATH . '/themes/' . THEME_NAME);
|
||||
|
||||
// Set the content width based on the theme's design and stylesheet
|
||||
if (!isset($content_width)) { $content_width = 940; }
|
||||
|
||||
@@ -1,31 +1,7 @@
|
||||
<?php
|
||||
|
||||
// header.php
|
||||
// head.php
|
||||
function roots_head() { do_action('roots_head'); }
|
||||
function roots_wrap_before() { do_action('roots_wrap_before'); }
|
||||
function roots_header_before() { do_action('roots_header_before'); }
|
||||
function roots_header_inside() { do_action('roots_header_inside'); }
|
||||
function roots_header_after() { do_action('roots_header_after'); }
|
||||
|
||||
// 404.php, archive.php, front-page.php, index.php, loop-page.php, loop-single.php,
|
||||
// loop.php, page-custom.php, page-full.php, page.php, search.php, single.php
|
||||
function roots_content_before() { do_action('roots_content_before'); }
|
||||
function roots_content_after() { do_action('roots_content_after'); }
|
||||
function roots_main_before() { do_action('roots_main_before'); }
|
||||
function roots_main_after() { do_action('roots_main_after'); }
|
||||
function roots_post_before() { do_action('roots_post_before'); }
|
||||
function roots_post_after() { do_action('roots_post_after'); }
|
||||
function roots_post_inside_before() { do_action('roots_post_inside_before'); }
|
||||
function roots_post_inside_after() { do_action('roots_post_inside_after'); }
|
||||
function roots_loop_before() { do_action('roots_loop_before'); }
|
||||
function roots_loop_after() { do_action('roots_loop_after'); }
|
||||
function roots_sidebar_before() { do_action('roots_sidebar_before'); }
|
||||
function roots_sidebar_inside_before() { do_action('roots_sidebar_inside_before'); }
|
||||
function roots_sidebar_inside_after() { do_action('roots_sidebar_inside_after'); }
|
||||
function roots_sidebar_after() { do_action('roots_sidebar_after'); }
|
||||
|
||||
// footer.php
|
||||
function roots_footer_before() { do_action('roots_footer_before'); }
|
||||
function roots_footer_inside() { do_action('roots_footer_inside'); }
|
||||
function roots_footer_after() { do_action('roots_footer_after'); }
|
||||
function roots_footer() { do_action('roots_footer'); }
|
||||
@@ -4,27 +4,20 @@
|
||||
*
|
||||
* Enqueue stylesheets in the following order:
|
||||
* 1. /theme/css/bootstrap.css
|
||||
* 2. /theme/css/bootstrap-responsive.css (if enabled in config.php)
|
||||
* 2. /theme/css/bootstrap-responsive.css
|
||||
* 3. /theme/css/app.css
|
||||
* 4. /child-theme/style.css (if a child theme is activated)
|
||||
*
|
||||
* Enqueue scripts in the following order:
|
||||
* 1. /theme/js/vendor/modernizr-2.6.1.min.js (in header.php)
|
||||
* 2. jquery-1.8.0.min.js via Google CDN (in header.php)
|
||||
* 1. /theme/js/vendor/modernizr-2.6.1.min.js (in head.php)
|
||||
* 2. jquery-1.8.0.min.js via Google CDN (in head.php)
|
||||
* 3. /theme/js/plugins.js
|
||||
* 4. /theme/js/main.js
|
||||
*/
|
||||
|
||||
function roots_scripts() {
|
||||
wp_enqueue_style('roots_bootstrap', get_template_directory_uri() . '/css/bootstrap.css', false, null);
|
||||
|
||||
if (current_theme_supports('bootstrap-responsive')) {
|
||||
wp_enqueue_style('roots_bootstrap_responsive', get_template_directory_uri() . '/css/bootstrap-responsive.css', array('roots_bootstrap'), null);
|
||||
}
|
||||
|
||||
// If you're not using Bootstrap, include HTML5 Boilerplate's main.css:
|
||||
// wp_enqueue_style('roots_h5bp', get_template_directory_uri() . '/css/main.css', false, null);
|
||||
|
||||
wp_enqueue_style('roots_bootstrap_responsive', get_template_directory_uri() . '/css/bootstrap-responsive.css', array('roots_bootstrap'), null);
|
||||
wp_enqueue_style('roots_app', get_template_directory_uri() . '/css/app.css', false, null);
|
||||
|
||||
// Load style.css from child theme
|
||||
|
||||
40
inc/util.php
40
inc/util.php
@@ -1,5 +1,44 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Theme Wrapper
|
||||
*
|
||||
* @link http://scribu.net/wordpress/theme-wrappers.html
|
||||
*/
|
||||
|
||||
function roots_template_path() {
|
||||
return Roots_Wrapping::$main_template;
|
||||
}
|
||||
|
||||
class Roots_Wrapping {
|
||||
|
||||
// Stores the full path to the main template file
|
||||
static $main_template;
|
||||
|
||||
// Stores the base name of the template file; e.g. 'page' for 'page.php' etc.
|
||||
static $base;
|
||||
|
||||
static function wrap($template) {
|
||||
self::$main_template = $template;
|
||||
|
||||
self::$base = substr(basename(self::$main_template), 0, -4);
|
||||
|
||||
if ('index' == self::$base) {
|
||||
self::$base = false;
|
||||
}
|
||||
|
||||
$templates = array('base.php');
|
||||
|
||||
if (self::$base) {
|
||||
array_unshift($templates, sprintf('base-%s.php', self::$base ));
|
||||
}
|
||||
|
||||
return locate_template($templates);
|
||||
}
|
||||
}
|
||||
|
||||
add_filter('template_include', array('Roots_Wrapping', 'wrap'), 99);
|
||||
|
||||
// returns WordPress subdirectory if applicable
|
||||
function wp_base_dir() {
|
||||
preg_match('!(https?://[^/|"]+)([^"]+)?!', site_url(), $matches);
|
||||
@@ -24,4 +63,3 @@ function add_filters($tags, $function) {
|
||||
add_filter($tag, $function);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user