<?php
// Add localisation support
load_theme_textdomain
( 'zendark', TEMPLATEPATH
. '/languages' );
$locale = get_locale
();
$locale_file = TEMPLATEPATH
."/languages/$locale.php";
if (is_readable($locale_file)) require_once($locale_file);
// Register theme options page
require_once(get_template_directory
().'/theme-options.php');
// Add default posts and comments RSS feed links to <head>.
add_theme_support
('automatic-feed-links');
// Set the content width based on the theme's design and stylesheet.
if (!isset($content_width)) $content_width = 700;
// This theme uses wp_nav_menu() in one location.
function zendark_register_nav_menu
() {
register_nav_menu
('primary', __
('Primary Menu', 'zendark'));
}
add_action
('init', 'zendark_register_nav_menu');
// Sets the post excerpt length to 40 words.
function zendark_excerpt_length
($length) {
return 40;
}
add_filter
('excerpt_length', 'zendark_excerpt_length');
// Returns a "Continue Reading" link for excerpts
function zendark_continue_reading_link
() {
return '<a href="'.esc_url
(get_permalink
()).'">'.__
('Continue reading ⇾', 'zendark').'</a>';
}
// Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and zendark_continue_reading_link().
function zendark_auto_excerpt_more
($more) {
return '…<br />'.zendark_continue_reading_link
();
}
add_filter
('excerpt_more', 'zendark_auto_excerpt_more');
// Display navigation to next/previous pages when applicable
function zendark_content_nav
( $nav_id ) {
global $wp_query;
if ( $wp_query->max_num_pages > 1 ) : ?>
<nav id="
<?php echo $nav_id; ?>">
<div class="nav-next">
<?php previous_posts_link
( __
('⇽ Newer posts', 'zendark')); ?></div>
<div class="nav-previous">
<?php next_posts_link
( __
('Older posts ⇾', 'zendark')); ?></div>
</nav><!-- #
<?php echo $nav_id; ?> -->
<?php endif;
}
// Count authors number (users with writing rights)
function zendark_count_authors
(){
$number = 0;
$result = count_users
();
foreach($result['avail_roles'] as $role => $count)
if($role != "subscriber") { $number = $number + $count; }
return $number;
}
// Register sidebars
function zendark_widgets_init
() {
register_sidebar
( array(
'name' => __
( 'Main Sidebar', 'zendark' ),
'id' => 'sidebar-1',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => "</aside>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}
add_action
('widgets_init', 'zendark_widgets_init');
/*
* Adds two classes to the array of body classes.
* The first is if the site has only had one author with published posts.
* The second is if a singular post being displayed
*/
function zendark_body_classes
($classes) {
if (!is_multi_author
()) { $classes[] = 'single-author'; }
if (is_singular
() && !is_home
()) $classes[] = 'singular';
return $classes;
}
add_filter
('body_class', 'zendark_body_classes');
// Get the first parent of a page
function zendark_get_root_parent
($page_id) {
global $wpdb;
$parent = $wpdb->get_var("SELECT post_parent FROM $wpdb->posts WHERE post_type='page' AND ID = '$page_id'");
if ($parent == 0) return $page_id;
else return zendark_get_root_parent
($parent);
}
// Add class to menu <li> for first parent page
add_filter
('nav_menu_css_class', 'zendark_special_nav_class', 10, 2);
function zendark_special_nav_class
($classes, $item){
if($item->object_id == zendark_get_root_parent
(get_the_ID
())){
$classes[] = "current_page_parent_function";
}
return $classes;
}
// This check if a gravatar exists for a user, and if not return false
function validate_gravatar
($email) {
/* first of all, we want to do the check only if it's needed, so
* we check that gravatars are actually enabled in settings, and
* that you want to display a blank avatar (no avatar) as default.
*/
if (get_option
('show_avatars') && get_option
('avatar_default') == 'blank') {
// Craft a potential url and test its headers
$hash = md5($email);
$uri = 'http://www.gravatar.com/avatar/'.$hash.'?d=404';
$headers = @get_headers($uri);
if (!preg_match("|200|", $headers[0])) $has_valid_avatar = false;
else $has_valid_avatar = true;
}
elseif (!get_option
('show_avatars')) $has_valid_avatar = false;
else $has_valid_avatar = true;
return $has_valid_avatar;
}
/* Function to generate comments, I believe it's
* necessary if you want paged comments.
*/
function zendark_comment
($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
if ($comment->comment_type != "trackback" && $comment->comment_type != "pingback") : ?>
<div id="comment-
<?php comment_ID
() ?>"
<?php comment_class
(); ?>>
<header class="comment-header">
<?php
if (validate_gravatar
(get_comment_author_email
()))
echo '<div class="comment-avatar">'.get_avatar
($comment, 40).'</div>';
?>
<div>
<div class="comment-meta">
<span class="comment-author">
<?php comment_author_link
() ?></span>
<?php edit_comment_link
( __
( 'Edit', 'zendark' ), ' • ', '' ); ?><br />
<?php printf('<span class="comment-datetime"><a href="%1$s"><time pubdate datetime="%2$s">%3$s</time></a></span>',
esc_url
(get_comment_link
($comment->comment_ID)),
get_comment_time
('c'),
/* translators: 1: date, 2: time */
sprintf(__
('%1$s %2$s', 'zendark'), get_comment_date
(), get_comment_time
())
); ?>
</div>
<?php comment_reply_link
(array_merge($args, array('reply_text' => __
( 'reply', 'zendark'), 'login_text' => __
( 'login to reply', 'zendark'), 'depth' => $depth, 'max_depth' => $args['max_depth']))); ?>
</div>
</header>
<div class="comment-content">
<?php if ($comment->comment_approved == '0') : ?>
<div class="comment-awaiting-moderation">
<?php _e
('Your comment is awaiting moderation', 'zendark'); ?></div>
<?php endif; ?>
<?php comment_text
(); ?>
</div>
</div>
<?php
endif;
}
// Function to generate trackback/pingback
function zendark_trackback
($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
if ($comment->comment_type == "trackback" || $comment->comment_type == "pingback") : ?>
<div id="comment-
<?php comment_ID
() ?>"
<?php comment_class
(); ?>>
<span class="comment-author">
<?php comment_author_link
() ?></span><br />
<?php comment_excerpt
(); ?>
</div>
<?php
endif;
}
// Function to count trackback/pingback
function zendark_trackback_number
($comments) {
$numero_trackback = 0;
foreach ($comments as $comment) :
if ($comment->comment_type == "trackback" || $comment->comment_type == "pingback") $numero_trackback++;
endforeach;
return $numero_trackback;
}
/* Function to generate both comments and trackbacks/pingbacks together,
* in case of paged comments. If you find a way to nicely separate comments
* and pingbacks/trackbacks in paged comments, please tell me.
*/
function zendark_all_comment
($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
if ($comment->comment_type != "trackback" && $comment->comment_type != "pingback") : ?>
<div id="comment-
<?php comment_ID
() ?>"
<?php comment_class
(); ?>>
<header class="comment-header">
<?php
if (validate_gravatar
(get_comment_author_email
()))
echo '<div class="comment-avatar">'.get_avatar
($comment, 40).'</div>';
?>
<div>
<div class="comment-meta">
<span class="comment-author">
<?php comment_author_link
() ?></span>
<?php edit_comment_link
( __
( 'Edit', 'zendark' ), ' • ', '' ); ?><br />
<?php printf('<span class="comment-datetime"><a href="%1$s"><time pubdate datetime="%2$s">%3$s</time></a></span>',
esc_url
(get_comment_link
($comment->comment_ID)),
get_comment_time
('c'),
/* translators: 1: date, 2: time */
sprintf(__
('%1$s %2$s', 'zendark'), get_comment_date
(), get_comment_time
())
); ?>
</div>
<?php comment_reply_link
(array_merge($args, array('reply_text' => __
( 'reply', 'zendark'), 'login_text' => __
( 'login to reply', 'zendark'), 'depth' => $depth, 'max_depth' => $args['max_depth']))); ?>
</div>
</header>
<div class="comment-content">
<?php if ($comment->comment_approved == '0') : ?>
<div class="comment-awaiting-moderation">
<?php _e
('Your comment is awaiting moderation', 'zendark'); ?></div>
<?php endif; ?>
<?php comment_text
(); ?>
</div>
</div>
<?php
endif;
if ($comment->comment_type == "trackback" || $comment->comment_type == "pingback") : ?>
<div id="comment-
<?php comment_ID
() ?>"
<?php comment_class
(); ?>>
<span class="comment-author">
<?php comment_author_link
() ?></span><br />
<?php comment_excerpt
(); ?>
</div>
<?php
endif;
}
?>