Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 430 lines (357 sloc) 14.341 kb
217f7fd Importing the News theme files and folders.
greenshady authored
1 <?php
2 /**
3 * The functions file is used to initialize everything in the theme. It controls how the theme is loaded and
4 * sets up the supported features, default actions, and default filters. If making customizations, users
5 * should create a child theme and make changes to its functions.php file (not this one). Friends don't let
6 * friends modify parent theme files. ;)
7 *
8 * Child themes should do their setup on the 'after_setup_theme' hook with a priority of 11 if they want to
9 * override parent theme features. Use a priority of 9 if wanting to run before the parent theme.
10 *
11 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License version 2, as published by the Free Software Foundation. You may NOT assume
13 * that you can use any other version of the GPL.
14 *
15 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
16 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 *
18 * You should have received a copy of the GNU General Public License along with this program; if not, write
19 * to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 * @package News
22 * @subpackage Functions
23 * @version 0.2.0
24 * @author DevPress <contact@devpress.com>
25 * @copyright Copyright (c) 2010 - 2011, DevPress LLC.
26 * @link http://devpress.com/themes/news
27 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
28 */
29
30 /* Load the core theme framework. */
31 require_once( trailingslashit( TEMPLATEPATH ) . 'library/hybrid.php' );
32 $theme = new Hybrid();
33
34 /* Do theme setup on the 'after_setup_theme' hook. */
35 add_action( 'after_setup_theme', 'news_theme_setup' );
36
37 /**
38 * Theme setup function. This function adds support for theme features and defines the default theme
39 * actions and filters.
40 *
41 * @since 0.1.0
42 */
43 function news_theme_setup() {
44
45 /* Get action/filter hook prefix. */
46 $prefix = hybrid_get_prefix();
47
48 /* Load shortcodes file. */
49 require_once( THEME_DIR . '/functions/shortcodes.php' );
50
51 /* Load admin functions. */
52 if ( is_admin() )
53 require_once( THEME_DIR . '/functions/admin.php' );
54
55 /* Add theme support for WordPress features. */
56 add_theme_support( 'automatic-feed-links' );
57
58 /* Add theme support for core framework features. */
59 add_theme_support( 'hybrid-core-menus', array( 'primary', 'secondary', 'subsidiary' ) );
60 add_theme_support( 'hybrid-core-sidebars', array( 'primary', 'secondary', 'header', 'after-singular' ) );
61 add_theme_support( 'hybrid-core-widgets' );
62 add_theme_support( 'hybrid-core-shortcodes' );
63 add_theme_support( 'hybrid-core-theme-settings', array( 'about', 'footer' ) );
64 add_theme_support( 'hybrid-core-seo' );
65 add_theme_support( 'hybrid-core-template-hierarchy' );
66
67 /* Add theme support for extensions. */
68 add_theme_support( 'dev-stylesheet' );
69 add_theme_support( 'loop-pagination' );
70 add_theme_support( 'get-the-image' );
71 add_theme_support( 'entry-views' );
72 add_theme_support( 'breadcrumb-trail' );
73
74 /* Register custom post types. */
75 add_action( 'init', 'news_register_post_types' );
76
77 /* Register shortcodes. */
78 add_action( 'init', 'news_register_shortcodes' );
79
80 /* Register new image sizes. */
81 add_action( 'init', 'news_register_image_sizes' );
82
83 /* Register additional widgets. */
84 add_action( 'widgets_init', 'news_register_widgets' );
85
86 /* Load JavaScript. */
87 add_action( 'wp_enqueue_scripts', 'news_enqueue_script' );
88
89 /* Site description. */
90 add_action( "{$prefix}_before_menu_secondary", 'hybrid_site_description' );
91
92 /* Hook additional items to the nav menus. */
93 add_filter( 'wp_nav_menu', 'news_nav_menu_add_items', 10, 2 );
94
95 /* Content. */
96 add_action( "{$prefix}_singular-post_after_loop", 'news_singular_post_tags' );
97
98 /* Tag cloud. */
99 add_filter( 'wp_tag_cloud', 'news_add_span_to_tag_cloud' );
100 add_filter( 'term_links-post_tag', 'news_add_span_to_tag_cloud' );
101
102 /* Embed width/height defaults. */
103 add_filter( 'embed_defaults', 'news_embed_defaults' );
104
105 /* Set content width. */
106 hybrid_set_content_width( 600 );
107
108 /* Allow all post types to have shortlinks. Do this early so plugins can still override. */
109 add_filter( 'get_shortlink', 'news_filter_shortlink', 1, 3 );
110
111 /* Add classes to the comments pagination. */
112 add_filter( 'previous_comments_link_attributes', 'news_previous_comments_link_attributes' );
113 add_filter( 'next_comments_link_attributes', 'news_next_comments_link_attributes' );
114
115 /* Add a wrapper class for singular videos. */
116 add_filter( 'the_content', 'news_video_embed_wrapper', 20 );
117
118 /* Shorter excerpt length. */
119 add_filter( 'excerpt_length', 'news_excerpt_length' );
120
121 /* Comment form arguments. */
122 add_filter( 'comment_form_defaults', 'news_comment_form_defaults', 11 );
123
124 /* Additional default theme settings. */
125 add_filter( "{$prefix}_default_theme_settings", 'news_theme_settings' );
126 }
127
128 /**
129 * Registers additional image sizes, in particular, the 'news-thumbnail' and 'news-slideshow' sizes.
130 *
131 * @since 0.1.0
132 */
133 function news_register_image_sizes() {
134 add_image_size( 'news-slideshow', 600, 400, true );
135 add_image_size( 'news-slideshow-large', 640, 430, true );
136 add_image_size( 'news-thumbnail', 100, 75, true );
137 }
138
139 /**
140 * Loads extra widget files and registers the widgets.
141 *
142 * @since 0.1.0
143 */
144 function news_register_widgets() {
145
146 /* Load the popular tabs widget. */
147 if ( current_theme_supports( 'entry-views' ) ) {
148 require_once( THEME_DIR . '/classes/widget-popular-tabs.php' );
149 register_widget( 'News_Widget_Popular_Tabs' );
150 }
151
152 /* Load the image stream widget. */
153 require_once( THEME_DIR . '/classes/widget-image-stream.php' );
154 register_widget( 'News_Widget_Image_Stream' );
155
156 /* Load the newsletter widget. */
157 require_once( THEME_DIR . '/classes/widget-newsletter.php' );
158 register_widget( 'News_Widget_Newsletter' );
159 }
160
161 /**
162 * Loads the theme JavaScript files.
163 *
164 * @since 0.1.0
165 */
166 function news_enqueue_script() {
167 wp_enqueue_script( 'jquery-ui-tabs' );
168 wp_enqueue_script( 'news-theme', THEME_URI . '/js/news-theme.js', array( 'jquery' ), 0.1, true );
169 }
170
171 /**
172 * Adds a log in/out link to the secondary menu.
173 *
174 * @since 0.1.0
175 */
176 function news_nav_menu_add_items( $menu, $args ) {
177
178 if ( 'secondary' == $args->theme_location ) {
179 $links = '<li class="loginout">' . wp_loginout( site_url( esc_url( $_SERVER['REQUEST_URI'] ) ), false ) . '</li>';
180 $menu = str_replace( '</ul></div>', $links . '</ul></div>', $menu );
181 }
182
183 return $menu;
184 }
185
186 /**
187 * Displays the post tags for singular posts.
188 *
189 * @since 0.1.0
190 */
191 function news_singular_post_tags() {
192 if ( has_tag() )
193 echo '<div class="entry-tags">' . do_shortcode( '[entry-terms type="post_tag" separator=""]' ) . '</div>';
194 }
195
196 /**
197 * Wraps tag cloud links with a span for easier background image styling.
198 *
199 * @todo If anyone can figure out a way to style this without the <span>, we can remove this.
200 *
201 * @since 0.1.0
202 */
203 function news_add_span_to_tag_cloud( $cloud ) {
204 $cloud = preg_replace( "/>(.*?)<\/a>/", "><span>$1</span></a>", $cloud );
205 return $cloud;
206 }
207
208 /**
209 * Adds 'class="prev" to the previous comments link.
210 *
211 * @since 0.1.0
212 */
213 function news_previous_comments_link_attributes( $attributes ) {
214 return $attributes . ' class="prev"';
215 }
216
217 /**
218 * Adds 'class="next" to the next comments link.
219 *
220 * @since 0.1.0
221 */
222 function news_next_comments_link_attributes( $attributes ) {
223 return $attributes . ' class="next"';
224 }
225
226 /**
227 * Returns the current comments page.
228 *
229 * @since 0.1.0
230 */
231 function news_get_current_comments_page() {
232 $cpage = get_query_var( 'cpage' );
233
234 return ( ( empty( $cpage ) ) ? 1 : absint( $cpage ) );
235 }
236
237 /**
238 * Custom comment form arguments.
239 *
240 * @since 0.2.0
241 * @param array $args The arguments for the comments form.
242 */
243 function news_comment_form_defaults( $args ) {
244
b67e8bf @justintadlock Change all instances of hybrid_get_textdomain() to 'news'.
authored
245 $args['label_submit'] = esc_attr__( 'Submit', 'news' );
217f7fd Importing the News theme files and folders.
greenshady authored
246
247 return $args;
248 }
249
250 /**
251 * Filters 'get_shortlink' because WordPress only creates shortlinks for the 'post' post type. We need
252 * a shortlink for pages and attachments. Note that this doesn't handle custom post types since we
253 * wouldn't really be making them "short" anyway. Most users looking for good shortlink solutions should
254 * use a shortlink plugin, especially when dealing with custom post types.
255 *
256 * @since 0.1.0
257 */
258 function news_filter_shortlink( $shortlink, $id, $context ) {
259
260 /* Get the post based on ID. */
261 $post = get_post( $id );
262
263 /* If not a post, just return the shortlink. */
264 if ( empty( $post ) )
265 return $shortlink;
266
267 /* Add a default shortlink for pages. */
268 if ( 'page' == $post->post_type )
269 $shortlink = home_url( "?page_id={$id}" );
270
271 /* Add a default shortlink for attachments. */
272 elseif ( 'attachment' == $post->post_type )
273 $shortlink = home_url( "?attachment_id={$id}" );
274
275 /* Return the shortlink. */
276 return $shortlink;
277 }
278
279 /**
280 * Adds "class='video-wrap'" to the opening <p> element around video embeds.
281 *
282 * @since 0.1.0
283 */
284 function news_video_embed_wrapper( $content ) {
285
286 if ( is_singular( 'video' ) && in_the_loop() )
287 $content = preg_replace( array( "/<p>(.*?)<object/", "/<p>(.*?)<iframe/" ), array( "<p class='video-wrap'>$1<object", "<p class='video-wrap'>$1<iframe" ), $content );
288
289 return $content;
290 }
291
292 /**
293 * Overwrites the default widths for embeds. This is especially useful for making sure videos properly
294 * expand the full width on video pages. This function overwrites what the $content_width variable handles
295 * with context-based widths.
296 *
297 * @since 0.1.0
298 */
299 function news_embed_defaults( $args ) {
300 if ( is_singular( 'video' ) || is_singular( 'slideshow' ) )
301 $args['width'] = 640;
302 else
303 $args['width'] = 560;
304
305 return $args;
306 }
307
308 /**
309 * Shortens the excerpt length so that auto-excerpts fit nicely into the design. This isn't bulletproof since
310 * the excerpt length is determined by words rather than characters. Child themes can also filter the
311 * 'excerpt_length' hook to make this longer or shorter.
312 *
313 * @since 0.1.0
314 */
315 function news_excerpt_length( $length ) {
316 return 40;
317 }
318
319 /**
320 * Add additional settings to the theme settings array.
321 *
322 * @since 0.1.0
323 */
324 function news_theme_settings( $settings ) {
325 $settings['home_template_categories'] = array();
326
327 return $settings;
328 }
329
330 /**
331 * Function for grabbing a post ID by meta key and meta value. We're using this in the sidebar-feature.php
332 * file to check if a page has been given the 'page-template-popular.php' page template.
333 *
334 * @since 0.1.0
335 */
336 function news_get_post_by_meta( $meta_key = '', $meta_value = '' ) {
337 global $wpdb;
338
339 $post_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s LIMIT 1", $meta_key, $meta_value ) );
340
341 if ( !empty( $post_id ) )
342 return $post_id;
343
344 return false;
345 }
346
347 /**
348 * Registers custom post types for the theme. We're registering the Video and Slideshow post types.
349 *
350 * Important! This will be removed in a future version and placed in an external plugin.
351 *
352 * @since 0.1.0
353 */
354 function news_register_post_types() {
355
b67e8bf @justintadlock Change all instances of hybrid_get_textdomain() to 'news'.
authored
356 $domain = 'news';
217f7fd Importing the News theme files and folders.
greenshady authored
357 $prefix = hybrid_get_prefix();
358
359 /* Labels for the video post type. */
360 $video_labels = array(
361 'name' => __( 'Videos', $domain ),
362 'singular_name' => __( 'Video', $domain ),
363 'add_new' => __( 'Add New', $domain ),
364 'add_new_item' => __( 'Add New Video', $domain ),
365 'edit' => __( 'Edit', $domain ),
366 'edit_item' => __( 'Edit Video', $domain ),
367 'new_item' => __( 'New Video', $domain ),
368 'view' => __( 'View Video', $domain ),
369 'view_item' => __( 'View Video', $domain ),
370 'search_items' => __( 'Search Videos', $domain ),
371 'not_found' => __( 'No videos found', $domain ),
372 'not_found_in_trash' => __( 'No videos found in Trash', $domain ),
373 );
374
375 /* Arguments for the video post type. */
376 $video_args = array(
377 'labels' => $video_labels,
378 'capability_type' => 'post',
379 'public' => true,
380 'can_export' => true,
381 'query_var' => true,
382 'rewrite' => array( 'slug' => 'videos', 'with_front' => false ),
383 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'custom-fields', 'comments', 'trackbacks', "{$prefix}-post-settings", 'entry-views' ),
384 );
385
386 /* Labels for the slideshow post type. */
387 $slideshow_labels = array(
388 'name' => __( 'Slideshows', $domain ),
389 'singular_name' => __( 'Slideshow', $domain ),
390 'add_new' => __( 'Add New', $domain ),
391 'add_new_item' => __( 'Add New Slideshow', $domain ),
392 'edit' => __( 'Edit', $domain ),
393 'edit_item' => __( 'Edit Slideshow', $domain ),
394 'new_item' => __( 'New Slideshow', $domain ),
395 'view' => __( 'View Slideshow', $domain ),
396 'view_item' => __( 'View Slideshow', $domain ),
397 'search_items' => __( 'Search Slideshows', $domain ),
398 'not_found' => __( 'No slideshows found', $domain ),
399 'not_found_in_trash' => __( 'No slideshows found in Trash', $domain ),
400 );
401
402 /* Arguments for the slideshow post type. */
403 $slideshow_args = array(
404 'labels' => $slideshow_labels,
405 'capability_type' => 'post',
406 'public' => true,
407 'can_export' => true,
408 'query_var' => true,
409 'rewrite' => array( 'slug' => 'slideshows', 'with_front' => false ),
410 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'custom-fields', 'comments', 'trackbacks', "{$prefix}-post-settings", 'entry-views' ),
411 );
412
413 /* Register the video post type. */
414 register_post_type( apply_filters( 'news_video_post_type', 'video' ), apply_filters( 'news_video_post_type_args', $video_args ) );
415
416 /* Register the slideshow post type. */
417 register_post_type( apply_filters( 'news_slideshow_post_type', 'slideshow' ), apply_filters( 'news_slideshow_post_type_args', $slideshow_args ) );
418 }
419
420 /* == Functions removed in version 0.2 == */
421
422 function news_get_header_sidebar() {}
423 function news_get_secondary_menu() {}
424 function news_get_subsidiary_menu() {}
425 function news_breadcrumb_trail_args() {}
426 function news_unregister_sidebars() {}
427 function news_register_sidebars() {}
428 function news_register_menus() {}
429
430 ?>
Something went wrong with that request. Please try again.