回答編集履歴
5
修正
answer
CHANGED
@@ -20,4 +20,22 @@
|
|
20
20
|
}
|
21
21
|
echo $stringify;
|
22
22
|
?></p>
|
23
|
+
```
|
24
|
+
|
25
|
+
質問者様による改訂案を将来の訪問者のために共有します
|
26
|
+
```php
|
27
|
+
<?php
|
28
|
+
$count = 2;
|
29
|
+
$tagchk = get_the_tags();
|
30
|
+
if($tagchk){ //get_the_tagsはタグがない場合、空配列ではなくfalseを返す
|
31
|
+
$wptags = array_slice(get_the_tags(), 0, $count);
|
32
|
+
echo '<p class="tag">';
|
33
|
+
foreach($wptags as $tag) {
|
34
|
+
$tagname = $tag->name;
|
35
|
+
$tagurl = get_tag_link( $tag->term_id );
|
36
|
+
echo '<a href="'.$tagurl.'">'.$tagname.'</a>';
|
37
|
+
}
|
38
|
+
echo '</p>';
|
39
|
+
}
|
40
|
+
?>
|
23
41
|
```
|
4
修正
answer
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
$count = 2; //2個?
|
5
5
|
|
6
6
|
$first2 = array_slice(get_the_tags(), 0, $count);
|
7
|
-
$first_2 = array_slice(explode(":", the_tags("", ":", "")), 0, $count); //:はタグで使わない文字である必要がある
|
7
|
+
//→出力されちゃう// $first_2 = array_slice(explode(":", the_tags("", ":", "")), 0, $count); //:はタグで使わない文字である必要がある
|
8
8
|
```
|
9
9
|
--
|
10
10
|
the_tagは出力関数でした。申し訳ないです。↓でどうでしょうか?
|
@@ -15,7 +15,8 @@
|
|
15
15
|
$wptags = array_slice(get_the_tags(), 0, $count);
|
16
16
|
$stringify = "";
|
17
17
|
foreach($wptags as $tag) {
|
18
|
+
$stringify .= '<a href="'.get_tag_link( $tag->term_id ).'">'.$tag->name.'</a> ' ;
|
18
|
-
$stringify .= $tag->name;
|
19
|
+
//$stringify .= $tag->name;
|
19
20
|
}
|
20
21
|
echo $stringify;
|
21
22
|
?></p>
|
3
修正
answer
CHANGED
@@ -12,7 +12,11 @@
|
|
12
12
|
<p class="tag"><?php
|
13
13
|
$count = 2; //2個?
|
14
14
|
|
15
|
-
$
|
15
|
+
$wptags = array_slice(get_the_tags(), 0, $count);
|
16
|
-
|
16
|
+
$stringify = "";
|
17
|
+
foreach($wptags as $tag) {
|
18
|
+
$stringify .= $tag->name;
|
19
|
+
}
|
20
|
+
echo $stringify;
|
17
21
|
?></p>
|
18
22
|
```
|
2
修正
answer
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
```php
|
4
4
|
$count = 2; //2個?
|
5
5
|
|
6
|
-
$first2 = array_slice(
|
6
|
+
$first2 = array_slice(get_the_tags(), 0, $count);
|
7
|
-
$first_2 = array_slice(explode(":",
|
7
|
+
$first_2 = array_slice(explode(":", the_tags("", ":", "")), 0, $count); //:はタグで使わない文字である必要がある
|
8
8
|
```
|
9
9
|
--
|
10
10
|
the_tagは出力関数でした。申し訳ないです。↓でどうでしょうか?
|
@@ -12,7 +12,7 @@
|
|
12
12
|
<p class="tag"><?php
|
13
13
|
$count = 2; //2個?
|
14
14
|
|
15
|
-
$first2 = array_slice(
|
15
|
+
$first2 = array_slice(get_the_tags(), 0, $count);
|
16
|
-
echo $first2;
|
16
|
+
echo implode("",$first2);
|
17
17
|
?></p>
|
18
18
|
```
|
1
修正
answer
CHANGED
@@ -5,4 +5,14 @@
|
|
5
5
|
|
6
6
|
$first2 = array_slice(get_the_tag(), 0, $count);
|
7
7
|
$first_2 = array_slice(explode(":", the_tag("", ":", "")), 0, $count); //:はタグで使わない文字である必要がある
|
8
|
+
```
|
9
|
+
--
|
10
|
+
the_tagは出力関数でした。申し訳ないです。↓でどうでしょうか?
|
11
|
+
```php
|
12
|
+
<p class="tag"><?php
|
13
|
+
$count = 2; //2個?
|
14
|
+
|
15
|
+
$first2 = array_slice(get_the_tag(), 0, $count);
|
16
|
+
echo $first2;
|
17
|
+
?></p>
|
8
18
|
```
|