-
Notifications
You must be signed in to change notification settings - Fork 232
/
functions.php
235 lines (186 loc) · 7.62 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?php
/*thanks to http://www.nathanrice.net/blog/wordpress-single-post-templates/ */
/*add_filter('single_template', create_function('$t', 'foreach( (array) get_the_category() as $cat ) { if ( file_exists(TEMPLATEPATH . "/single-{$cat->category_nicename}.php") ) return TEMPLATEPATH . "/single-{$cat->category_nicename}.php"; } return $t;' ));*/
add_filter('single_template', create_function('$t', 'foreach( (array) get_the_category() as $cat ) {
if ( file_exists(TEMPLATEPATH . "/single-{$cat->category_nicename}.php") ) return TEMPLATEPATH . "/single-{$cat->category_nicename}.php";
else if($cat->category_parent!=0){
$pCat=$cat;
while($pCat->cat_ID) {
if ( file_exists(TEMPLATEPATH . "/single-{$pCat->category_nicename}.php") ) return TEMPLATEPATH . "/single-{$pCat->category_nicename}.php";
$pCat=get_category($pCat->category_parent);
}
}
} return $t;' ));
function fs_register_menus() {
register_nav_menus(array('primary' => __( 'Primary Navigation' )));
}
/**
* @package WordPress
* @subpackage Default_Theme
*/
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Sub Header',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
));
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Navigation',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
));
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Index Right Aside',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
));
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name' => 'Post Left Aside',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
));
}
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name' => 'Post Right Aside',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
));
}
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Post Footer',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
));
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Footer',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
));
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Heel',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
));
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => '404',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
));
function new_excerpt_more($more) { return '...'; }
function excerpt_read_more($post) { return '<a href="'. get_permalink($post->ID) . '">' . 'Read On...' . '</a>'; }
/*
function truncate_title($title, $length, $echo=true)
{
if (strlen($title) > $length) $title=substr($title, 0, $length).'…';
if($echo) echo $title;
return $title;
}
*/
function content($maxLength, $read_more="Read More", $image_width=190, $image_height=120, $image_quality=80, $autolink=false, $echo=true)
{
$content = get_the_content($read_more);
$pattern = '/\< *[img][^\>]* src *= *[\"\']{0,1}([^\"\'\ >]*)/i';
$replacement = '<img src="' . get_bloginfo("template_directory") . '/php/timthumb/timthumb.php.php?src=' . '$1' . '&w='.$image_width.'&h='.$image_height.'&q='.$image_quality;
$pagecontent = preg_replace($pattern, $replacement, $content);
if($echo) echo $pagecontent;
return $pagecontent;
}
/**
* Add "first" and "last" CSS classes to dynamic sidebar widgets. Also adds numeric index class for each widget (widget-1, widget-2, etc.)
* via http://wordpress.org/support/topic/how-to-first-and-last-css-classes-for-sidebar-widgets
*/
function 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"
return $params;
}
add_filter('dynamic_sidebar_params','widget_first_last_classes');
// ======================
// = HOME PAGE SECTIONS =
// ======================
function franklin_st_home()
{
include 'admin/admin-options-home.php';
}
function franklin_st_general()
{
include 'admin/admin-options-general.php';
}
// add our menus
function franklin_street_admin_menu()
{
add_menu_page( 'Franklin Street', 'Franklin Street', 'manage_options', 'franklin-street', 'franklin_st_general' );
add_submenu_page( 'franklin-street', 'Franklin Street', 'General', 'manage_options', 'franklin-street', 'franklin_st_general');
add_submenu_page( 'franklin-street', 'Franklin Street', 'Home Page Sections', 'manage_options', 'franklin-street-home', 'franklin_st_home');
/*
* TODO:
* Add a customize submenu for additional CSS & Javascript to be put in the header and footer
*/
}
add_action( 'admin_menu', 'franklin_street_admin_menu' );
function franklin_street_admin_assets()
{
if( is_admin() )
{
wp_enqueue_script( 'jquery-ui-sortable' );
wp_enqueue_style( 'franklin-street-admin', get_bloginfo( 'stylesheet_directory' ) . '/admin/css/franklin-street-options.css', NULL, NULL, NULL );
wp_enqueue_script( 'franklin-street-admin', get_bloginfo( 'stylesheet_directory' ) . '/admin/js/franklin-street-utils.js', 'jquery', NULL, true );
}
}
add_action( 'init', 'franklin_street_admin_assets' );
function franklin_street_footer() {
$franklin_street_general = get_option( '_franklin_street_general' );
if($franklin_street_general) echo $franklin_street_general['footer'];
}
function franklin_street_header() {
$franklin_street_general = get_option( '_franklin_street_general' );
if($franklin_street_general) echo $franklin_street_general['header'];
}
add_action('wp_footer', 'franklin_street_footer');
add_action('wp_head', 'franklin_street_header');
?>