-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
151 lines (142 loc) · 5.24 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
<?php
include_once 'lib/b4-wp-navwalker.php';
if ( ! isset( $content_width ) ) $content_width = 837;
class B4_Theme
{
const VERSION = '1.0';
//
function __construct()
{
add_action('widgets_init', [$this, 'widgets_init']);
add_action('after_setup_theme', [$this, 'setup']);
add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts']);
add_filter('nav_menu_css_class', [$this, 'nav_li_class'], 10, 2);
add_filter('nav_menu_link_attributes', [$this, 'nav_anchor_class'], 10, 3 );
add_action('comment_form_before', [$this, 'comment_form_before'], 10, 5 );
add_filter('comment_form_defaults', [$this, 'comment_form'], 10, 5 );
add_action('comment_form_after', [$this, 'comment_form_after'], 10, 5 );
}
//
function widgets_init()
{
register_sidebar([
'name' => __('Right Sidebar', 'b4'),
'id' => 'right-sidebar',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3>',
'after_title' => '</h3>',
]);
}
//
function setup()
{
add_theme_support('custom-background', ['default-color' => 'ffffff']);
add_theme_support('automatic-feed-links' );
add_theme_support('title-tag' );
add_theme_support('html5', ['search-form', 'comment-form', 'comment-list', 'gallery', 'caption']);
register_nav_menus(['main_menu' => __( 'Main Menu', 'b4')]);
add_editor_style( 'css/bootstrap.min.css' );
}
//
function enqueue_scripts()
{
wp_enqueue_style('font-awesome', get_template_directory_uri() . '/css/font-awesome.min.css', [], '4.4.0' );
wp_register_style('bootstrap', get_template_directory_uri() . '/css/bootstrap.min.css', [], self::VERSION );
wp_enqueue_style('styles', get_stylesheet_uri(), ['bootstrap'], '1' );
wp_enqueue_script('bootstrap', get_template_directory_uri() . '/js/bootstrap.js', ['jquery'], self::VERSION, true );
}
//
function nav_li_class($classes, $item)
{
$classes[] .= ' nav-item';
return $classes;
}
//
function nav_anchor_class( $atts, $item, $args )
{
$atts['class'] .= ' nav-link';
return $atts;
}
//
function comment_form_before()
{
echo '<div class="card"><div class="card-block">';
}
//
function comment_form( $fields )
{
$fields['fields']['author'] = '
<fieldset class="form-group comment-form-email">
<label for="author">' . __( 'Name *', 'b4' ) . '</label>
<input type="text" class="form-control" name="author" id="author" placeholder="' . __( 'Name', 'b4' ) . '" aria-required="true" required>
</fieldset>';
$fields['fields']['email'] ='
<fieldset class="form-group comment-form-email">
<label for="email">' . __( 'Email address *', 'b4' ) . 'Email address *</label>
<input type="email" class="form-control" id="email" placeholder="' . __( 'Enter email', 'b4' ) . '" aria-required="true" required>
<small class="text-muted">' . __( 'Your email address will not be published.', 'b4' ) . '</small>
</fieldset>';
$fields['fields']['url'] = '
<fieldset class="form-group comment-form-email">
<label for="url">' . __( 'Website *', 'b4' ) . '</label>
<input type="text" class="form-control" name="url" id="url" placeholder="' . __( 'http://example.org', 'b4' ) . '">
</fieldset>';
$fields['comment_field'] = '
<fieldset class="form-group">
<label for="comment">' . __( 'Comment *', 'b4' ) . '</label>
<textarea class="form-control" id="comment" name="comment" rows="3" aria-required="true" required></textarea>
</fieldset>';
$fields['comment_notes_before'] = '';
$fields['class_submit'] = 'btn btn-primary';
return $fields;
}
//
function comment_form_after()
{
echo '</div><!-- .card-block --></div><!-- .card -->';
}
//
function get_posts_pagination( $args = '' )
{
global $wp_query;
$pagination = '';
if ( $GLOBALS['wp_query']->max_num_pages > 1 )
{
$defaults = [
'total' => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1,
'current' => get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1,
'type' => 'array',
'prev_text' => '«',
'next_text' => '»',
];
$params = wp_parse_args($args, $defaults);
$paginate = paginate_links($params);
if( $paginate )
{
$pagination .= "<ul class='pagination'>";
foreach( $paginate as $page )
{
if (strpos( $page, 'current' ))
{
$pagination .= "<li class='active'>$page</li>";
}
else
{
$pagination .= "<li>$page</li>";
}
}
$pagination .= "</ul>";
}
}
return $pagination;
}
//
function the_posts_pagination($args = '')
{
echo $this->get_posts_pagination( $args );
}
//
}
$b4 = new B4_Theme;
?>