質問編集履歴
1
function\.phpに追記したコードを記載致しました。コードブロックで囲んだ内容で修正致しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,114 @@
|
|
1
1
|
ワードプレスのタグクラウドにカテゴリーごとにタグを表示し、一部のタグを非表示にしたいのですが、非表示の方法がわかりません。
|
2
2
|
|
3
3
|
|
4
|
+
|
5
|
+
function.php へ記述
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
```ここに言語を入力
|
10
|
+
|
11
|
+
function my_category_tag_cloud($args) {
|
12
|
+
|
13
|
+
$defaults = array(
|
14
|
+
|
15
|
+
'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
|
16
|
+
|
17
|
+
'format' => 'flat', 'separator' => "\n", 'orderby' => 'name', 'order' => 'ASC',
|
18
|
+
|
19
|
+
'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'echo' => true
|
20
|
+
|
21
|
+
);
|
22
|
+
|
23
|
+
$args = wp_parse_args( $args, $defaults );
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
global $wpdb;
|
28
|
+
|
29
|
+
$query = "
|
30
|
+
|
31
|
+
SELECT DISTINCT terms2.term_id as term_id, terms2.name as name, t2.count as count
|
32
|
+
|
33
|
+
FROM
|
34
|
+
|
35
|
+
$wpdb->posts as p1
|
36
|
+
|
37
|
+
LEFT JOIN $wpdb->term_relationships as r1 ON p1.ID = r1.object_ID
|
38
|
+
|
39
|
+
LEFT JOIN $wpdb->term_taxonomy as t1 ON r1.term_taxonomy_id = t1.term_taxonomy_id
|
40
|
+
|
41
|
+
LEFT JOIN $wpdb->terms as terms1 ON t1.term_id = terms1.term_id,
|
42
|
+
|
43
|
+
$wpdb->posts as p2
|
44
|
+
|
45
|
+
LEFT JOIN $wpdb->term_relationships as r2 ON p2.ID = r2.object_ID
|
46
|
+
|
47
|
+
LEFT JOIN $wpdb->term_taxonomy as t2 ON r2.term_taxonomy_id = t2.term_taxonomy_id
|
48
|
+
|
49
|
+
LEFT JOIN $wpdb->terms as terms2 ON t2.term_id = terms2.term_id
|
50
|
+
|
51
|
+
WHERE
|
52
|
+
|
53
|
+
t1.taxonomy = 'category' AND p1.post_status = 'publish' AND terms1.term_id = " . $args['cat'] . " AND
|
54
|
+
|
55
|
+
t2.taxonomy = 'post_tag' AND p2.post_status = 'publish'
|
56
|
+
|
57
|
+
AND p1.ID = p2.ID
|
58
|
+
|
59
|
+
";
|
60
|
+
|
61
|
+
$tags = $wpdb->get_results($query);
|
62
|
+
|
63
|
+
foreach ( $tags as $key => $tag ) {
|
64
|
+
|
65
|
+
if ( 'edit' == $args['link'] )
|
66
|
+
|
67
|
+
$link = get_edit_tag_link( $tag->term_id, $args['taxonomy'] );
|
68
|
+
|
69
|
+
else
|
70
|
+
|
71
|
+
$link = get_term_link( intval($tag->term_id), $args['taxonomy'] );
|
72
|
+
|
73
|
+
if ( is_wp_error( $link ) )
|
74
|
+
|
75
|
+
return false;
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
$tags[ $key ]->link = $link;
|
80
|
+
|
81
|
+
$tags[ $key ]->id = $tag->term_id;
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
$return = wp_generate_tag_cloud( $tags, $args );
|
88
|
+
|
89
|
+
$return = apply_filters( 'wp_tag_cloud', $return, $args );
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
if ( 'array' == $args['format'] || empty($args['echo']) )
|
94
|
+
|
95
|
+
return $return;
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
echo $return;
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
```
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
表示する場所へ記述
|
110
|
+
|
111
|
+
```ここに言語を入力
|
4
112
|
|
5
113
|
<?php
|
6
114
|
|
@@ -18,6 +126,8 @@
|
|
18
126
|
|
19
127
|
?>
|
20
128
|
|
129
|
+
```
|
130
|
+
|
21
131
|
|
22
132
|
|
23
133
|
こちらでカテゴリーごとのタグ表示はできました。
|
@@ -27,3 +137,9 @@
|
|
27
137
|
この中からタグID23と33と35を非表示にしたいのですが、
|
28
138
|
|
29
139
|
どうすればいいかご教示いただけないでしょうか?
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
2017年6月19日 13:37分
|
144
|
+
|
145
|
+
質問内容を修正致しました。
|