/
widget.php
84 lines (77 loc) · 2.9 KB
/
widget.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
<?php //ウィジェット操作関連の関数
/**
* Cocoon WordPress Theme
* @author: yhira
* @link: https://wp-cocoon.com/
* @license: http://www.gnu.org/licenses/gpl-2.0.html GPL v2 or later
*/
if ( !defined( 'ABSPATH' ) ) exit;
//タグクラウドのカスタマイズ
add_filter( 'widget_tag_cloud_args', 'widget_tag_cloud_args_custom' );
if ( !function_exists( 'widget_tag_cloud_args_custom' ) ):
function widget_tag_cloud_args_custom($args) {
$defaults = array(
'orderby' => 'count', //使用頻度順
'order' => 'DESC', // 降順(使用頻度の高い順)
'number' => 60, // 表示数
);
$args = wp_parse_args($args, $defaults);
//var_dump($args);
return $args;
}
endif;
//カテゴリウィジェットの投稿数のカッコを取り除く
add_filter( 'wp_list_categories', 'remove_post_count_parentheses', 10, 2 );
add_filter( 'get_archives_link', 'remove_post_count_parentheses', 10, 2 );
if ( !function_exists( 'remove_post_count_parentheses' ) ):
function remove_post_count_parentheses( $output, $var ) {
$output = preg_replace('/<\/a>.*\(([0-9,]+)\)/','<span class="post-count">$1</span></a>',$output);
return $output;
}
endif;
//タグクラウドの出力変更
add_filter( 'wp_tag_cloud', 'wp_tag_cloud_custom', 10, 2);
if ( !function_exists( 'wp_tag_cloud_custom' ) ):
function wp_tag_cloud_custom( $output, $args ) {
//style属性を取り除く
$output = preg_replace( '/\s*?style="[^"]+?"/i', '', $output);
//タグテキストにspanタグの取り付け
$output = preg_replace( '/ aria-label="([^"]+?)">/i', ' aria-label="$1"><span class="tag-caption"><span class="fa fa-tag tax-icon" aria-hidden="true"></span>', $output);
//数字を表示しているとき
if (isset($args['show_count']) && $args['show_count']) {
$output = str_replace( '<span class="tag-link-count">', '</span><span class="tag-link-count">', $output);
//_v($output);
//カッコを取り除く
$output = str_replace( '<span class="tag-link-count"> (', '<span class="tag-link-count">', $output);
$output = str_replace( ')</span>', '</span>', $output);
} else {//数字を表示しないとき
$output = str_replace( '</a>', '</span></a>', $output);
}
return $output;
}
endif;
if ( !function_exists( 'is_first_char_exclamation' ) ):
function is_first_char_exclamation($title){
if (strpos($title, '!') === 0) {
return true;
}
}
endif;
if ( !function_exists( 'is_widget_title_visible' ) ):
function is_widget_title_visible($title){
if ($title && !is_first_char_exclamation($title)) {
return true;
}
}
endif;
//ウィジェットのタイトルを隠せるように
add_filter('widget_title', 'widget_title_hidable');
if ( !function_exists( 'widget_title_hidable' ) ):
function widget_title_hidable($title){
//ウィジェットタイトルの最初の一文字が!のとき
if (is_first_char_exclamation($title)) {
return null;
}
return $title;
}
endif;