-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
executable file
·138 lines (113 loc) · 5.17 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
/**
* @package WordPress
* @subpackage monochromatic
*/
add_action( 'after_setup_theme', 'monochromatic_theme_setup' );
function monochromatic_theme_setup() {
/* Content Width */
if ( ! isset( $content_width ) ) $content_width = 1200;
/* Comment Reply Script */
if ( is_singular() ) wp_enqueue_script( 'comment-reply' );
/* Add Theme Support for Menus */
add_theme_support( 'menus' );
register_nav_menu( 'navigation', 'Navigation Bar' );
/* Automatic RSS Links (useful for feed readers) */
add_theme_support( 'automatic-feed-links' );
/* Adds support for Post Thumbnails */
add_theme_support( 'post-thumbnails' );
/* Allows for shortcodes in widgets */
add_filter('widget_text', 'do_shortcode');
add_action( 'widgets_init', 'monochromatic_register_right_sidebars' );
add_action( 'widgets_init', 'monochromatic_register_footer_sidebars' );
add_filter('dynamic_sidebar_params','monochromatic_widget_first_last_classes');
/* Add Theme Editor to Admin Bar (to save time!) */
add_action( 'admin_bar_menu', 'monochromatic_admin_bar_theme_editor_option', 100 );
/* Customized Comment Display */
if ( ! function_exists( 'monochromatic_comments' ) ) :
function monochromatic_comments($comment, $args, $depth) {
$GLOBALS['comment'] = $comment; ?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID() ?>">
<div id="comment-<?php comment_ID(); ?>" class="single-comment clearfix">
<div class="comment-author vcard"> <?php echo get_avatar($comment,$size='64'); ?></div>
<div class="comment-meta commentmetadata">
<?php if ($comment->comment_approved == '0') : ?>
<em><?php _e('Comment is awaiting moderation','monochromatic');?></em> <br />
<?php endif; ?>
<h6><?php echo __('By','monochromatic').' '.get_comment_author_link(). ' '. get_comment_date(). ' - ' . get_comment_time(); ?></h6>
<?php comment_text() ?>
<?php edit_comment_link(__('Edit comment','monochromatic'),' ',''); ?>
<?php comment_reply_link(array_merge( $args, array('reply_text' => __('Reply','monochromatic'),'depth' => $depth, 'max_depth' => $args['max_depth']))); ?>
</div>
</div>
<!-- </li> -->
<?php }
endif;
}
/* Right Sidebar Setup */
function monochromatic_register_right_sidebars() {
register_sidebar(array(
'name' => 'Right Sidebar',
'id' => 'right-sidebar',
'description' => 'Widgets in this area will be shown on the right-hand side.',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h4 class="widgettitle">',
'after_title' => '</h4>',
));
}
/* Footer Widgets Sidebar Setup */
function monochromatic_register_footer_sidebars() {
register_sidebar(array(
'name' => 'Footer Sidebar',
'id' => 'footer-sidebar',
'description' => 'Widgets in this area will be shown in the footer_widgets area.',
'before_widget' => '<div id="%1$s" class="one-third column widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4 class="widgettitle">',
'after_title' => '</h4>',
));
}
/* Add "first" and "last" CSS classes to dynamic sidebar widgets. */
/* Also adds numeric index class for each widget (widget-1, widget-2, etc.) */
function monochromatic_widget_first_last_classes($params) {
global $my_widget_num; // Global a counter array
$this_id = $params[0]['id']; // Get the id for the current sidebar we're processing
$arr_registered_widgets = wp_get_sidebars_widgets(); // Get an array of ALL registered widgets
if(!$my_widget_num) {// If the counter array doesn't exist, create it
$my_widget_num = array();
}
if(!isset($arr_registered_widgets[$this_id]) || !is_array($arr_registered_widgets[$this_id])) { // Check if the current sidebar has no widgets
return $params; // No widgets in this sidebar... bail early.
}
if(isset($my_widget_num[$this_id])) { // See if the counter array has an entry for this sidebar
$my_widget_num[$this_id] ++;
} else { // If not, create it starting with 1
$my_widget_num[$this_id] = 1;
}
$class = 'class="widget-' . $my_widget_num[$this_id] . ' '; // Add a widget number class for additional styling options
if($my_widget_num[$this_id] == 1) { // If this is the first widget
$class .= 'widget-first ';
} elseif($my_widget_num[$this_id] == count($arr_registered_widgets[$this_id])) { // If this is the last widget
$class .= 'widget-last ';
}
//$params[0]['before_widget'] = str_replace('class="', $class, $params[0]['before_widget']); // Insert our new classes into "before widget"
$params[0]['before_widget'] = preg_replace('/class=\"/', "$class", $params[0]['before_widget'], 1);
return $params;
}
/* Adds Edit Theme to Bar */
function monochromatic_admin_bar_theme_editor_option() {
global $wp_admin_bar;
if ( !is_super_admin() || !is_admin_bar_showing() )
return;
$wp_admin_bar->add_menu(
array( 'id' => 'edit-theme',
'title' => __("Edit Theme", 'monochromatic'),
'href' => '' . home_url() . '/wp-admin/theme-editor.php'
)
);
}
/* Theme Options Panel */
require_once ( get_template_directory() . '/inc/theme-options.php' );
/* monochromatic Hooks */
require_once ( get_template_directory() . '/inc/hooks.php' );