-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
executable file
·310 lines (282 loc) · 11.3 KB
/
Copy pathfunctions.php
File metadata and controls
executable file
·310 lines (282 loc) · 11.3 KB
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<?php
/*------------------------------------*\
系统 功能
\*------------------------------------*/
//移除<P>标签
remove_filter( 'the_content', 'wpautop' ); //正文
remove_filter( 'the_excerpt', 'wpautop' ); //摘要
/*------------------------------------*\
菜单 功能
\*------------------------------------*/
// 注册菜单
function hao_menu() {
register_nav_menus(array(
'header-menu' => '主菜单',
'sidebar-menu' => '边栏菜单',
'footer-menu' => '底部菜单'
));
}
add_action('init', 'hao_menu');
// 移除默认导航多余<div> <ul>
function my_wp_nav_menu_args($args = '') {
$args['container'] = false;
$args['items_wrap'] = '%3$s';
return $args;
}
add_filter('wp_nav_menu_args', 'my_wp_nav_menu_args');
// 移除菜单 <li> 中的 id class
function my_css_attributes_filter($var) {
// return is_array($var) ? array() : ''; // 全部移除
return is_array($var) ? array_intersect($var, array('current-menu-item')) : ''; // 保留高亮项
}
add_filter('nav_menu_css_class', 'my_css_attributes_filter', 100, 1);
add_filter('nav_menu_item_id', 'my_css_attributes_filter', 100, 1);
add_filter('page_css_class', 'my_css_attributes_filter', 100, 1);
/*------------------------------------*\
无限加载infinite scroll
\*------------------------------------*/
function infinite_scroll_js() {
if (!is_singular() ) {
?>
<script type="text/javascript">
function loadImg(){
$('.box-img img').each(function() {
var img = new Image();
if($(this).attr('original')){
img.src = $(this).attr('original');
} else {
img.src = $(this)[0].src;
}
if(img.complete) {
console.log('该图片已经存在于缓存之中,不会再去重新下载');
$(this).prev().addClass('hide');
$(this).removeClass('hide');
} else {
$(this).load(function(){
// console.log($.inArray($(this)[0], $('.box-img img')));
$(this).prev().addClass('hide');
$(this).removeClass('hide');
});
}
setTimeout(function(){
$(this).prev().addClass('hide');
$(this).removeClass('hide');
},1500);
});
}
<?php if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')){?>
loadImg();
<?php }?>
// loadImg();
// alert("<?php echo $_SERVER['HTTP_USER_AGENT'];?>")
jQuery(document).ready(function(){
<?php if(!strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')){?>
loadImg();
<?php }?>
});
</script>
<?php
}?>
<?php
if (is_singular() ) {
?>
<script type="text/javascript">
var loadImg = function(){
$('.box-img img').each(function() {
var img = new Image();
img.src = $(this)[0].src;
if(img.complete) {
console.log('该图片已经存在于缓存之中,不会再去重新下载');
$(this).prev().addClass('hide');
$(this).removeClass('hide');
} else {
$(this).load(function(){
// console.log($.inArray($(this)[0], $('.box-img img')));
$(this).prev().addClass('hide');
$(this).removeClass('hide');
});
}
setTimeout(function(){
$(this).prev().addClass('hide');
$(this).removeClass('hide');
},1500);
});
}
<?php if(strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')){?>
loadImg();
<?php }?>
jQuery(document).ready(function(){
<?php if(!strpos($_SERVER['HTTP_USER_AGENT'],'MSIE')){?>
loadImg();
<?php }?>
});
</script>
<?php
}
}
add_action('wp_footer', 'infinite_scroll_js', 100);
require_once dirname( __FILE__ ) . '/theme-options.php'; // 加载主题选项文件
/**
* 获取WordPress所有分类名字和ID
* <?php show_category(); ?>
*/
function show_category(){
global $wpdb;
$request = "SELECT $wpdb->terms.term_id, name FROM $wpdb->terms ";
$request .= " LEFT JOIN $wpdb->term_taxonomy ON $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id ";
$request .= " WHERE $wpdb->term_taxonomy.taxonomy = 'category' ";
$request .= " ORDER BY term_id asc";
$categorys = $wpdb->get_results($request);
foreach ($categorys as $category) { //调用菜单
$output = '<li>'.$category->name."[<strong>".$category->term_id.'</strong>]</li>';
echo $output;
}
}
/**------------------------------
* 商品信息输入面板
---------------------------------*/
$hao_meta_boxes = array(
"hao_zhutu" => array(
"name" => "hao_zhutu",
"describe" => "请填入图片地址,如:http://xbaba.cn/img.jpg",
"std" => "",
"title" => "商品图片:"),
"hao_xianj" => array(
"name" => "hao_xianj",
"describe" => "直接填入商品现价&券后价。如:29.9",
"std" => "",
"title" => "商品现价:"),
"hao_yuanj" => array(
"name" => "hao_yuanj",
"describe" => "直接填入商品原价。如:39.9",
"std" => "",
"title" => "商品原价:"),
"hao_youh" => array(
"name" => "hao_youh",
"describe" => "直接填入优惠券的面额。如:10",
"std" => "",
"title" => "优惠金额:"),
"hao_ljgm" => array(
"name" => "hao_ljgm",
"describe" => "直接写入商品购买链接或领券链接",
"std" => "",
"title" => "购买链接:"),
"hao_xiaol" => array(
"name" => "hao_xiaol",
"describe" => "直接填入商品销量。如:8991",
"std" => "",
"title" => "产品销量:"),
"hao_zongl" => array(
"name" => "hao_zongl",
"describe" => "直接填入商品优惠券的总数量。如:100000",
"std" => "",
"title" => "优惠券量:"),
"hao_leix" => array(
"name" => "hao_leix",
"describe" => "请填入:淘宝或天猫",
"std" => "",
"title" => "店铺类型:")
);
function hao_meta_boxes() {
global $post, $hao_meta_boxes;
foreach($hao_meta_boxes as $meta_box) {
$meta_box_value = get_post_meta($post->ID, $meta_box['name'].'', true);
if($meta_box_value == "")
$meta_box_value = $meta_box['std'];
echo '<table><tr><td><h4>'.$meta_box['title'].'</h4></td>';
echo '<td><textarea cols="50" rows="1" name="'.$meta_box['name'].'">'.$meta_box_value.'</textarea></td>';
echo '<td><p>'.$meta_box['describe'].'</p></td></tr></table>';
}
echo '<input type="hidden" name="dj_metaboxes_nonce" id="dj_metaboxes_nonce" value="'.wp_create_nonce( plugin_basename(__FILE__) ).'" />';
}
function create_meta_box() {
global $theme_name;
if ( function_exists('add_meta_box') ) {
add_meta_box( 'hao-meta-boxes', '商品信息', 'hao_meta_boxes', 'post', 'normal', 'high' );
}
}
function save_postdata( $post_id ) {
global $hao_meta_boxes;
if ( !wp_verify_nonce( $_POST['dj_metaboxes_nonce'], plugin_basename(__FILE__) ))
return;
if ( !current_user_can( 'edit_posts', $post_id ))
return;
foreach($hao_meta_boxes as $meta_box) {
$data = $_POST[$meta_box['name'].''];
if($data == "")
delete_post_meta($post_id, $meta_box['name'].'', get_post_meta($post_id, $meta_box['name'].'', true));
else
update_post_meta($post_id, $meta_box['name'].'', $data);
}
}
add_action('admin_menu', 'create_meta_box');
add_action('save_post', 'save_postdata');
function hao_admin_js() {
?>
<script src="<?php bloginfo('template_url'); ?>/ui/jquery.js" type="text/javascript" ></script>
<script>
jQuery(document).ready(function(){
$("#postdivrich").before($("#hao-meta-boxes"));
})
</script>
<?php
}
add_action( 'admin_head', 'hao_admin_js' );
/**
* 添加输出菜单描述的 Walker 类
* https://www.wpdaxue.com/wp_nav_menu-output-description.html
*/
class description_walker extends Walker_Nav_Menu
{
function start_el(&$output, $item, $depth = 0, $args = array(), $id = 0)
{
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
$class_names = ' class="'. esc_attr( $class_names ) . '"';
$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
$prepend = '<span >';
$append = '</span>';
$description = ! empty( $item->description ) ? '<span class="iconfont">'.esc_attr( $item->description ).'</span>' : '';
if($depth != 0)
{
$description = $append = $prepend = "";
}
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
$item_output .= $description.$args->link_after;
$item_output .= $args->link_before .$prepend.apply_filters( 'the_title', $item->title, $item->ID ).$append;
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args,$id );
}
}
function timeago( $ptime ) {
$ptime = strtotime($ptime);
$etime = time() - $ptime;
if ($etime < 1) return '刚刚';
$interval = array (
12 * 30 * 24 * 60 * 60 => '年前 ('.date('Y-m-d', $ptime).')',
30 * 24 * 60 * 60 => '个月前 ('.date('m-d', $ptime).')',
7 * 24 * 60 * 60 => '周前 ('.date('m-d', $ptime).')',
24 * 60 * 60 => '天前',
60 * 60 => '小时前',
60 => '分钟前',
1 => '秒前'
);
foreach ($interval as $secs => $str) {
$d = $etime / $secs;
if ($d >= 1) {
$r = round($d);
return $r . $str;
}
};
}
include 'schedule.php';
?>