-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.php
123 lines (112 loc) · 3.61 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
<?php
function catch_everything() {
global $post, $posts;
$first_img = '';
$match = array();
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches[1][0];
if ( $first_img != '' ) {
return $first_img;
}
preg_match('#https?://www\.youtube(?:\-nocookie)?\.com/embed/([A-Za-z0-9\-_]+)#', $post->post_content, $match);
if ( $match[1] != '' ) {
return 'http://img.youtube.com/vi/'.$match[1].'/0.jpg';
}
preg_match('#(?:https?(?:a|vh?)?://)?(?:www\.)?youtube(?:\-nocookie)?\.com/watch\?.*v=([A-Za-z0-9\-_]+)#', $post->post_content, $match);
if ( $match[1] != '' ) {
return 'http://img.youtube.com/vi/'.$match[1].'/0.jpg';
}
preg_match('#http://player\.vimeo\.com/video/([0-9]+)#', $post->post_content, $match);
if ( $match[1] != '' ) {
$hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$match[1].php"));
return $hash[0]['thumbnail_large'];
}
preg_match('#(?:http://)?(?:www\.)?vimeo\.com/([A-Za-z0-9\-_]+)#', $post->post_content, $match);
if ( $match[1] != '' ) {
$hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$match[1].php"));
return $hash[0]['thumbnail_large'];
}
else {
return 'http://placehold.it/750x400/2ecc71/ffffff/&text=Default+Image';
}
}
function custom_excerpt_length( $length ) {
return 64;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
function new_excerpt_more( $more ) {
return '...';
}
add_filter('excerpt_more', 'new_excerpt_more');
function excerpt_read_more_link($output) {
global $post;
return $output . '<a href="'. get_permalink($post->ID) . '"><button class="gap-bottom asphalt">Read More</button></a>';
}
add_filter('the_excerpt', 'excerpt_read_more_link');
add_action('after_setup_theme', 'groundworker_setup');
function blankslate_setup()
{
load_theme_textdomain('groundworker', get_template_directory() . '/languages');
add_theme_support('automatic-feed-links');
add_theme_support('post-thumbnails');
global $content_width;
if ( ! isset( $content_width ) ) $content_width = 640;
register_nav_menus(
array( 'main-menu' => __( 'Main Menu', 'groundworker' ) )
);
}
add_action('wp_enqueue_scripts', 'groundworker_load_scripts');
function groundworker_load_scripts()
{
wp_enqueue_script('jquery');
}
add_action('comment_form_before', 'groundworker_enqueue_comment_reply_script');
function groundworker_enqueue_comment_reply_script()
{
if (get_option('thread_comments')) { wp_enqueue_script('comment-reply'); }
}
add_filter('the_title', 'groundworker_title');
function groundworker_title($title) {
if ($title == '') {
return '→';
} else {
return $title;
}
}
add_filter('wp_title', 'groundworker_filter_wp_title');
function groundworker_filter_wp_title($title)
{
return $title . esc_attr(get_bloginfo('name'));
}
add_action('widgets_init', 'groundworker_widgets_init');
function groundworker_widgets_init()
{
register_sidebar( array (
'name' => __('Sidebar Widget Area', 'groundworker'),
'id' => 'primary-widget-area',
'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
'after_widget' => "</li>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
}
function groundworker_custom_pings($comment)
{
$GLOBALS['comment'] = $comment;
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>"><?php echo comment_author_link(); ?></li>
<?php
}
add_filter('get_comments_number', 'groundworker_comments_number');
function groundworker_comments_number($count)
{
if (!is_admin()) {
global $id;
$comments_by_type = &separate_comments( get_comments( 'status=approve&post_id=' . $id ) );
return count($comments_by_type['comment']);
} else {
return $count;
}
}