Merge pull request #554 from retlehs/move_html_into_templates

Move HTML into templates
This commit is contained in:
Scott Walkinshaw
2012-09-19 13:04:07 -07:00
12 changed files with 39 additions and 62 deletions

View File

@@ -1,3 +1,9 @@
### HEAD
* Move custom entry_meta code into template
* Move Google Analytics code into footer template
* Add CONTRIBUTING.md to assist with the new GitHub UI
* Add nav walker support for CSS dividers and nav-header
### 6.0.0: September 16th, 2012
* Simplify nav walker and support 3rd level dropdowns
* Update to Bootstrap 2.1.1, jQuery 1.8.1, Modernizr 2.6.2

View File

@@ -3,14 +3,6 @@ table of contents](README.md)
# Theme library
### actions.php
This file is used to hook into [WordPress actions](http://codex.wordpress.org/Plugin_API/Action_Reference).
The `roots_feed_link()` function is used to hook into `wp_head()` to return a feed link if your site has any posts.
The `roots_google_analytics()` function is used to hook into `wp_footer()` to return the [asynchronous Google Analytics snippet](http://mathiasbynens.be/notes/async-analytics-snippet) from HTML5 Boilerplate if an ID is defined in `config.php`.
### activation.php
This file handles the theme activation. [About the theme activation](activation.md).
@@ -106,13 +98,6 @@ Learn about `plugins.js` and `main.js` in the HTML5 Boilerplate [JavaScript docs
It's safe to move jQuery to the footer if you're able to avoid problems with certain plugins that improperly use jQuery. Copy the necessary lines from `head.php` to `footer.php` right before `wp_footer()`, then update the `wp_register_script()` calls `scripts.php` to have scripts in the footer by setting the last argument to `true`.
### template-tags.php
This file contains custom template tags.
`roots_entry_meta()` is used by the [theme templates](templates.md) to return the author byline and post time and date information.
### utils.php
This file contains utility functions used by other files in the theme.
@@ -126,4 +111,4 @@ This file registers the custom sidebars and custom widgets. There are two initia
1. Primary Sidebar (used by `templates/sidebar.php`, included from `base.php` within `#sidebar`)
2. Footer (used by `templates/footer.php`)
The included vCard widget can be used to build additional, custom widgets.
The included vCard widget can be used to build additional, custom widgets.

View File

@@ -19,10 +19,16 @@ The `content-page.php` template is included by page templates in the theme root.
The `content-single.php` template is included by single post templates in the theme root.
### entry-meta.php
`entry-meta.php` displays the author byline, post time, and date information.
### footer.php
`footer.php` includes the Footer sidebar area and displays the site copyright information.
Also included is the [asynchronous Google Analytics snippet](http://mathiasbynens.be/notes/async-analytics-snippet) from HTML5 Boilerplate if an ID is defined in `config.php`.
### head.php
`head.php` includes everything in the `<head>`.
@@ -45,4 +51,4 @@ The `content-single.php` template is included by single post templates in the th
### sidebar.php
`sidebar.php` includes the Primary Sidebar.
`sidebar.php` includes the Primary Sidebar.

View File

@@ -11,8 +11,6 @@ require_once locate_template('/lib/activation.php'); // Theme activation
require_once locate_template('/lib/cleanup.php'); // Cleanup
require_once locate_template('/lib/htaccess.php'); // Rewrites for assets, H5BP .htaccess
require_once locate_template('/lib/widgets.php'); // Sidebars and widgets
require_once locate_template('/lib/template-tags.php'); // Template tags
require_once locate_template('/lib/actions.php'); // Actions
require_once locate_template('/lib/scripts.php'); // Scripts and stylesheets
require_once locate_template('/lib/post-types.php'); // Custom post types
require_once locate_template('/lib/metaboxes.php'); // Custom metaboxes

View File

@@ -1,31 +0,0 @@
<?php
/**
* Add the RSS feed link in the <head> if there's posts
*/
function roots_feed_link() {
$count = wp_count_posts('post'); if ($count->publish > 0) {
echo "\n\t<link rel=\"alternate\" type=\"application/rss+xml\" title=\"". get_bloginfo('name') ." Feed\" href=\"". home_url() ."/feed/\">\n";
}
}
add_action('wp_head', 'roots_feed_link', -2);
/**
* Add the asynchronous Google Analytics snippet from HTML5 Boilerplate
* if an ID is defined in config.php
*
* @link mathiasbynens.be/notes/async-analytics-snippet
*/
function roots_google_analytics() {
if (GOOGLE_ANALYTICS_ID) {
echo "\n\t<script>\n";
echo "\t\tvar _gaq=[['_setAccount','" . GOOGLE_ANALYTICS_ID . "'],['_trackPageview']];\n";
echo "\t\t(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];\n";
echo "\t\tg.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';\n";
echo "\t\ts.parentNode.insertBefore(g,s)}(document,'script'));\n";
echo "\t</script>\n";
}
}
add_action('wp_footer', 'roots_google_analytics');

View File

@@ -1,7 +0,0 @@
<?php
// Return post entry meta information
function roots_entry_meta() {
echo '<time class="updated" datetime="'. get_the_time('c') .'" pubdate>'. sprintf(__('Posted on %s at %s.', 'roots'), get_the_date(), get_the_time()) .'</time>';
echo '<p class="byline author vcard">'. __('Written by', 'roots') .' <a href="'. get_author_posts_url(get_the_author_meta('ID')) .'" rel="author" class="fn">'. get_the_author() .'</a></p>';
}

View File

@@ -68,3 +68,8 @@ function is_element_empty($element) {
$element = trim($element);
return empty($element) ? false : true;
}
function has_posts() {
$count = wp_count_posts('post');
return ($count->publish > 0) ? true : false;
}

View File

@@ -2,7 +2,7 @@
<article <?php post_class() ?> id="post-<?php the_ID(); ?>">
<header>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php roots_entry_meta(); ?>
<?php get_template_part('templates/entry-meta'); ?>
</header>
<div class="entry-content">
<?php the_content(); ?>
@@ -13,4 +13,4 @@
</footer>
<?php comments_template('/templates/comments.php'); ?>
</article>
<?php endwhile; ?>
<?php endwhile; ?>

View File

@@ -10,7 +10,7 @@
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php roots_entry_meta(); ?>
<?php get_template_part('templates/entry-meta'); ?>
</header>
<div class="entry-content">
<?php the_excerpt(); ?>

2
templates/entry-meta.php Normal file
View File

@@ -0,0 +1,2 @@
<time class="updated" datetime="<?php echo get_the_time('c'); ?>" pubdate><?php echo sprintf(__('Posted on %s at %s.', 'roots'), get_the_date(), get_the_time()); ?></time>
<p class="byline author vcard"><?php echo __('Written by', 'roots'); ?> <a href="<?php echo get_author_posts_url(get_the_author_meta('ID')); ?>" rel="author" class="fn"><?php echo get_the_author(); ?></a></p>

View File

@@ -3,4 +3,13 @@
<p>&copy; <?php echo date('Y'); ?> <?php bloginfo('name'); ?></p>
</footer>
<?php wp_footer(); ?>
<?php if (GOOGLE_ANALYTICS_ID): ?>
<script>
var _gaq=[['_setAccount','<?php echo GOOGLE_ANALYTICS_ID; ?>'],['_trackPageview']];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];
g.src=('https:'==location.protocol?'//ssl':'//www')+'.google-analytics.com/ga.js';
s.parentNode.insertBefore(g,s)}(document,'script'));
</script>
<?php endif; ?>
<?php wp_footer(); ?>

View File

@@ -14,4 +14,8 @@
<script>window.jQuery || document.write('<script src="<?php echo get_template_directory_uri(); ?>/assets/js/vendor/jquery-1.8.1.min.js"><\/script>')</script>
<?php wp_head(); ?>
</head>
<?php if (has_posts()): ?>
<link rel="alternate" type="application/rss+xml" title="<?php echo get_bloginfo('name') ?> Feed" href="<?php echo home_url() ?>/feed/">
<?php endif; ?>
</head>