質問編集履歴
9
文章追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
|
21
21
|
### 該当のソースコード
|
22
22
|
|
23
|
-
↓↓↓新着記事ウィジットのPHP↓↓↓
|
23
|
+
↓↓↓新着記事ウィジットのPHP(親テーマ内のfunctions.php)↓↓↓
|
24
24
|
|
25
25
|
|
26
26
|
|
8
文章追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -145,3 +145,35 @@
|
|
145
145
|
|
146
146
|
|
147
147
|
参考にしている記事 → [https://www.studiobrain.net/10958](https://www.studiobrain.net/10958)
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
### 追記
|
162
|
+
|
163
|
+
CHERRYさんの教えていただいた通りにコードを変えてみましたができませんでした。
|
164
|
+
|
165
|
+
```php
|
166
|
+
|
167
|
+
function fit_recent_widget_registration() {
|
168
|
+
|
169
|
+
unregister_widget('wp_widget_recent_posts'); //ここを↓に持ってきてもダメでした
|
170
|
+
|
171
|
+
if ( is_single() ){
|
172
|
+
|
173
|
+
register_widget('fit_recent_posts_widget');
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
```
|
7
文章追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
|
17
|
-
分かる方がいましたら教えていただけると嬉しいです。よろしくお願い致します。
|
17
|
+
WordPressもPHPも初心者なので、分かる方がいましたら教えていただけると嬉しいです。よろしくお願い致します。
|
18
18
|
|
19
19
|
|
20
20
|
|
@@ -116,6 +116,24 @@
|
|
116
116
|
|
117
117
|
```
|
118
118
|
|
119
|
+
### 試したこと
|
120
|
+
|
121
|
+
参考にしている記事 → [https://www.studiobrain.net/10958](https://www.studiobrain.net/10958)
|
122
|
+
|
123
|
+
こちらの「★トップページ(ホームとフロントページ)にだけ表示したくない場合」のコードの中に上記のコードをそのまま入れてみましたがエラーが起こります。
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
```php
|
128
|
+
|
129
|
+
<?php if ( !is_home() && !is_front_page() ) : ?>
|
130
|
+
|
131
|
+
ここに上記の「新着記事ウィジェットアイテムのフォーマット変更(サムネイル追加)」の中身をコピー
|
132
|
+
|
133
|
+
<?php endif; ?>
|
134
|
+
|
135
|
+
```
|
136
|
+
|
119
137
|
|
120
138
|
|
121
139
|
### 補足情報(FW/ツールのバージョンなど)
|
6
内容変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
WordPress
|
1
|
+
WordPress ウィジットをページにより非表示にしたい
|
test
CHANGED
@@ -10,15 +10,7 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
-
こちらの
|
14
|
-
|
15
|
-
・記事ページ、ページタイトル後ろの背景アイキャッチ画像
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
の部分のアイキャッチ部分をいじりたいのですが、どうやら子テーマ内に変更部分が見つからず、多分親テーマ内のfunctions.phpを触らないといけないようです。
|
20
|
-
|
21
|
-
|
13
|
+
こちらのサイドバーにある「最近の投稿」などの項目をトップページでは非表示に、記事ページでは表示するよう変更したいです。
|
22
14
|
|
23
15
|
|
24
16
|
|
@@ -28,49 +20,99 @@
|
|
28
20
|
|
29
21
|
### 該当のソースコード
|
30
22
|
|
31
|
-
↓↓↓
|
23
|
+
↓↓↓新着記事ウィジットのPHP↓↓↓
|
32
24
|
|
33
25
|
|
34
26
|
|
35
27
|
```php
|
36
28
|
|
37
|
-
|
29
|
+
//////////////////////////////////////////////////
|
38
30
|
|
39
|
-
|
31
|
+
//新着記事ウィジェットアイテムのフォーマット変更(サムネイル追加)
|
40
32
|
|
41
|
-
|
33
|
+
//////////////////////////////////////////////////
|
42
34
|
|
43
|
-
|
35
|
+
class fit_recent_posts_widget extends wp_widget_recent_posts {
|
44
36
|
|
45
|
-
|
37
|
+
function widget($args, $instance) {
|
46
38
|
|
47
|
-
|
39
|
+
extract( $args );
|
48
40
|
|
49
|
-
|
41
|
+
$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title'], $instance, $this->id_base);
|
50
42
|
|
51
|
-
|
43
|
+
|
52
44
|
|
53
|
-
|
45
|
+
if( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
|
54
46
|
|
55
|
-
|
47
|
+
$number = 10;
|
56
48
|
|
49
|
+
|
57
50
|
|
51
|
+
$r = new WP_Query( apply_filters( 'widget_posts_args', array( 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true ) ) );
|
58
52
|
|
59
|
-
|
53
|
+
if( $r->have_posts() ) :
|
60
54
|
|
55
|
+
|
61
56
|
|
57
|
+
echo $before_widget;
|
62
58
|
|
63
|
-
|
59
|
+
if( $title ) echo $before_title . $title . $after_title; ?>
|
64
60
|
|
65
|
-
<
|
61
|
+
<ol class="imgListWidget">
|
66
62
|
|
67
|
-
<?php
|
63
|
+
<?php while( $r->have_posts() ) : $r->the_post(); ?>
|
68
64
|
|
69
|
-
<
|
65
|
+
<li class="imgListWidget__item">
|
70
66
|
|
71
|
-
<img
|
67
|
+
<a class="imgListWidget__borderBox" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><span>
|
72
68
|
|
69
|
+
<?php if ( has_post_thumbnail()): ?>
|
70
|
+
|
71
|
+
<?php the_post_thumbnail('thumbnail'); ?>
|
72
|
+
|
73
|
+
<?php else: ?>
|
74
|
+
|
75
|
+
<img src="<?php echo get_template_directory_uri(); ?>/img/img_no_thumbnail.gif" alt="NO IMAGE">
|
76
|
+
|
73
|
-
<?php endif
|
77
|
+
<?php endif; ?>
|
78
|
+
|
79
|
+
</span></a>
|
80
|
+
|
81
|
+
<h3 class="imgListWidget__title">
|
82
|
+
|
83
|
+
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
|
84
|
+
|
85
|
+
<?php if( !empty( $instance['show_date'] )): ?><span class="post-date"><?php the_time('Y.m.d'); ?></span><?php endif; ?>
|
86
|
+
|
87
|
+
</h3>
|
88
|
+
|
89
|
+
</li>
|
90
|
+
|
91
|
+
<?php endwhile; ?>
|
92
|
+
|
93
|
+
</ol>
|
94
|
+
|
95
|
+
<?php
|
96
|
+
|
97
|
+
echo $after_widget;
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
wp_reset_postdata();
|
102
|
+
|
103
|
+
endif;
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
function fit_recent_widget_registration() {
|
110
|
+
|
111
|
+
unregister_widget('wp_widget_recent_posts'); register_widget('fit_recent_posts_widget');
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
add_action('widgets_init', 'fit_recent_widget_registration');
|
74
116
|
|
75
117
|
```
|
76
118
|
|
@@ -84,4 +126,4 @@
|
|
84
126
|
|
85
127
|
|
86
128
|
|
87
|
-
参考にしている記事 → [https://
|
129
|
+
参考にしている記事 → [https://www.studiobrain.net/10958](https://www.studiobrain.net/10958)
|
5
内容変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -34,17 +34,23 @@
|
|
34
34
|
|
35
35
|
```php
|
36
36
|
|
37
|
-
if(
|
37
|
+
if(is_single()) {
|
38
38
|
|
39
|
-
|
39
|
+
if(has_post_thumbnail()) {
|
40
40
|
|
41
|
-
|
41
|
+
$thumbnail = get_the_post_thumbnail_url( get_the_ID(), 'icatch' );
|
42
42
|
|
43
|
-
|
43
|
+
}else{
|
44
44
|
|
45
|
-
|
45
|
+
$thumbnail = get_template_directory_uri().'/img/img_no.gif';
|
46
46
|
|
47
|
+
}
|
48
|
+
|
49
|
+
echo '
|
50
|
+
|
47
|
-
|
51
|
+
.singleTitle {background-image:url("'.$thumbnail.'");}'."\n";
|
52
|
+
|
53
|
+
}
|
48
54
|
|
49
55
|
```
|
50
56
|
|
4
内容変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -46,18 +46,6 @@
|
|
46
46
|
|
47
47
|
echo '.singleTitle {background-image:url("'.$thumbnail.'");}'."\n";
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
if ( get_option('fit_theme_infoHead') == 'value2' && get_theme_mod('fit_theme_infoHeadColor') != '#c53929') {
|
52
|
-
|
53
|
-
$infoHeadColor = esc_attr( get_theme_mod( 'fit_theme_infoHeadColor' ));
|
54
|
-
|
55
|
-
echo '
|
56
|
-
|
57
|
-
.infoHead{background-color:'.$infoHeadColor.';}'."\n";
|
58
|
-
|
59
|
-
}
|
60
|
-
|
61
49
|
```
|
62
50
|
|
63
51
|
|
3
内容変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,97 +14,55 @@
|
|
14
14
|
|
15
15
|
・記事ページ、ページタイトル後ろの背景アイキャッチ画像
|
16
16
|
|
17
|
+
|
18
|
+
|
19
|
+
の部分のアイキャッチ部分をいじりたいのですが、どうやら子テーマ内に変更部分が見つからず、多分親テーマ内のfunctions.phpを触らないといけないようです。
|
20
|
+
|
17
|
-
|
21
|
+
自分なりにここを変更すればできるかなという部分を見つけたのですが、PHPにあまり詳しくないのでなかなか成功しません。
|
18
22
|
|
19
23
|
|
20
24
|
|
21
|
-
の部分のアイキャッチ部分をいじりたいのですが、どうやら親テーマ内のfunctions.phpを触らないといけないようです。
|
22
|
-
|
23
|
-
直でいじってみたり、子テーマを親テーマの後から動かすようにして上書きしようとしてみましたがエラーが出てしまい修正できません。
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
分かる方がいましたら教えていただけると嬉しいです。よろしくお願い致します。
|
28
26
|
|
29
27
|
|
30
28
|
|
31
29
|
### 該当のソースコード
|
32
30
|
|
33
|
-
↓↓↓親テーマ
|
31
|
+
↓↓↓親テーマfunctions.phpの一部分です。多分ここが記事タイトル背景のアイキャッチ設定部分かと思われます↓↓↓
|
34
32
|
|
35
33
|
|
36
34
|
|
37
35
|
```php
|
38
36
|
|
39
|
-
|
37
|
+
if(has_post_thumbnail()) {
|
40
38
|
|
41
|
-
|
39
|
+
$thumbnail = get_the_post_thumbnail_url( get_the_ID(), 'icatch' );
|
42
40
|
|
43
|
-
|
41
|
+
}else{
|
44
42
|
|
45
|
-
'orderby' => 'meta_value_num',
|
46
|
-
|
47
|
-
'order' => 'DESC',
|
48
|
-
|
49
|
-
'ignore_sticky_posts' => '1',
|
50
|
-
|
51
|
-
'posts_per_page' => $number
|
52
|
-
|
53
|
-
);
|
54
|
-
|
55
|
-
$my_query = new WP_Query( $args );?>
|
56
|
-
|
57
|
-
<ol class="rankListWidget">
|
58
|
-
|
59
|
-
<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
|
60
|
-
|
61
|
-
<li class="rankListWidget__item<?php if ( get_option('fit_post_eyecatch') == 'value2' ) : ?> rankListWidget__item-noeye<?php endif; ?>">
|
62
|
-
|
63
|
-
|
43
|
+
$thumbnail = get_template_directory_uri().'/img/img_no.gif';
|
64
|
-
|
65
|
-
<div class="eyecatch eyecatch-widget u-txtShdw">
|
66
|
-
|
67
|
-
<a href="<?php the_permalink(); ?>">
|
68
|
-
|
69
|
-
<?php if(has_post_thumbnail()) {the_post_thumbnail('icatch');} else {echo '<img src="'.get_template_directory_uri().'/img/img_no.gif" alt="NO IMAGE"/>';}?>
|
70
|
-
|
71
|
-
</a>
|
72
|
-
|
73
|
-
</div>
|
74
|
-
|
75
|
-
<?php endif; ?>
|
76
|
-
|
77
|
-
<h3 class="rankListWidget__title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
|
78
|
-
|
79
|
-
<div class="dateList dateList-widget<?php if ( get_option('fit_post_eyecatch') == 'value2' ) : ?> dateList-noeye<?php endif; ?>">
|
80
|
-
|
81
|
-
<?php if(!empty($instance['time'])) : ?><span class="dateList__item icon-calendar"><?php the_time('Y.m.d'); ?></span><?php endif; ?>
|
82
|
-
|
83
|
-
<span class="dateList__item icon-folder"><?php the_category(' ');?></span>
|
84
|
-
|
85
|
-
</div>
|
86
|
-
|
87
|
-
</li>
|
88
|
-
|
89
|
-
<?php endwhile; wp_reset_postdata(); ?>
|
90
|
-
|
91
|
-
</ol>
|
92
|
-
|
93
|
-
<?php
|
94
|
-
|
95
|
-
echo $after_widget;
|
96
|
-
|
97
|
-
}
|
98
44
|
|
99
45
|
}
|
100
46
|
|
47
|
+
echo '.singleTitle {background-image:url("'.$thumbnail.'");}'."\n";
|
48
|
+
|
49
|
+
|
50
|
+
|
101
|
-
|
51
|
+
if ( get_option('fit_theme_infoHead') == 'value2' && get_theme_mod('fit_theme_infoHeadColor') != '#c53929') {
|
52
|
+
|
53
|
+
$infoHeadColor = esc_attr( get_theme_mod( 'fit_theme_infoHeadColor' ));
|
54
|
+
|
55
|
+
echo '
|
56
|
+
|
57
|
+
.infoHead{background-color:'.$infoHeadColor.';}'."\n";
|
58
|
+
|
59
|
+
}
|
102
60
|
|
103
61
|
```
|
104
62
|
|
105
63
|
|
106
64
|
|
107
|
-
↓↓↓
|
65
|
+
↓↓↓アイキャッチに関する部分を下記のコードに変更したいです↓↓↓
|
108
66
|
|
109
67
|
|
110
68
|
|
2
内容変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -13,8 +13,6 @@
|
|
13
13
|
こちらの
|
14
14
|
|
15
15
|
・記事ページ、ページタイトル後ろの背景アイキャッチ画像
|
16
|
-
|
17
|
-
・サイドバー、「最近の投稿」のアイキャッチ画像
|
18
16
|
|
19
17
|
・サイドバー、「記事ランキング」のアイキャッチ画像 ※デモページにはありませんが設定できます
|
20
18
|
|
@@ -32,99 +30,75 @@
|
|
32
30
|
|
33
31
|
### 該当のソースコード
|
34
32
|
|
35
|
-
↓↓↓親テーマ内のfunctions.phpの変更したい部分の1つです↓↓↓
|
33
|
+
↓↓↓親テーマ内のfunctions.phpの変更したい部分の1つ(記事ランキング)です↓↓↓
|
36
34
|
|
37
35
|
|
38
36
|
|
39
37
|
```php
|
40
38
|
|
41
|
-
|
39
|
+
get_the_ID();
|
42
40
|
|
43
|
-
|
41
|
+
$args = array(
|
44
42
|
|
45
|
-
|
43
|
+
'meta_key'=> 'post_views_count',
|
46
44
|
|
47
|
-
|
45
|
+
'orderby' => 'meta_value_num',
|
48
46
|
|
49
|
-
|
47
|
+
'order' => 'DESC',
|
50
48
|
|
51
|
-
|
49
|
+
'ignore_sticky_posts' => '1',
|
52
50
|
|
53
|
-
|
51
|
+
'posts_per_page' => $number
|
54
52
|
|
55
|
-
|
53
|
+
);
|
56
54
|
|
57
|
-
|
55
|
+
$my_query = new WP_Query( $args );?>
|
58
56
|
|
59
|
-
|
57
|
+
<ol class="rankListWidget">
|
60
58
|
|
61
|
-
|
59
|
+
<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
|
62
60
|
|
63
|
-
|
61
|
+
<li class="rankListWidget__item<?php if ( get_option('fit_post_eyecatch') == 'value2' ) : ?> rankListWidget__item-noeye<?php endif; ?>">
|
64
62
|
|
65
|
-
if(
|
63
|
+
<?php if ( get_option('fit_post_eyecatch') != 'value2' ) : ?>
|
66
64
|
|
67
|
-
|
65
|
+
<div class="eyecatch eyecatch-widget u-txtShdw">
|
68
66
|
|
69
|
-
e
|
67
|
+
<a href="<?php the_permalink(); ?>">
|
70
68
|
|
71
|
-
|
69
|
+
<?php if(has_post_thumbnail()) {the_post_thumbnail('icatch');} else {echo '<img src="'.get_template_directory_uri().'/img/img_no.gif" alt="NO IMAGE"/>';}?>
|
72
70
|
|
73
|
-
<
|
71
|
+
</a>
|
74
72
|
|
75
|
-
|
73
|
+
</div>
|
76
74
|
|
77
|
-
|
75
|
+
<?php endif; ?>
|
78
76
|
|
79
|
-
|
77
|
+
<h3 class="rankListWidget__title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
|
80
78
|
|
81
|
-
|
79
|
+
<div class="dateList dateList-widget<?php if ( get_option('fit_post_eyecatch') == 'value2' ) : ?> dateList-noeye<?php endif; ?>">
|
82
80
|
|
83
|
-
|
81
|
+
<?php if(!empty($instance['time'])) : ?><span class="dateList__item icon-calendar"><?php the_time('Y.m.d'); ?></span><?php endif; ?>
|
84
82
|
|
85
|
-
<?php e
|
83
|
+
<span class="dateList__item icon-folder"><?php the_category(' ');?></span>
|
86
84
|
|
87
|
-
|
85
|
+
</div>
|
88
86
|
|
89
|
-
|
87
|
+
</li>
|
90
88
|
|
91
|
-
|
89
|
+
<?php endwhile; wp_reset_postdata(); ?>
|
92
90
|
|
93
|
-
|
91
|
+
</ol>
|
94
92
|
|
95
|
-
|
93
|
+
<?php
|
96
94
|
|
97
|
-
|
95
|
+
echo $after_widget;
|
98
96
|
|
99
|
-
</h3>
|
100
|
-
|
101
|
-
</li>
|
102
|
-
|
103
|
-
<?php endwhile; ?>
|
104
|
-
|
105
|
-
</ol>
|
106
|
-
|
107
|
-
<?php
|
108
|
-
|
109
|
-
echo $after_widget;
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
wp_reset_postdata();
|
114
|
-
|
115
|
-
endif;
|
116
|
-
|
117
|
-
|
97
|
+
}
|
118
98
|
|
119
99
|
}
|
120
100
|
|
121
|
-
function fit_recent_widget_registration() {
|
122
|
-
|
123
|
-
unregister_widget('wp_widget_recent_posts'); register_widget('fit_recent_posts_widget');
|
124
|
-
|
125
|
-
}
|
126
|
-
|
127
|
-
add_action('widgets_init',
|
101
|
+
add_action( 'widgets_init', create_function( '', 'return register_widget( "Popular_Posts" );' ) );
|
128
102
|
|
129
103
|
```
|
130
104
|
|
1
内容変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
WordPress
|
1
|
+
WordPress 親テーマのfunctions.phpの中身を変更したい
|
test
CHANGED
@@ -20,13 +20,9 @@
|
|
20
20
|
|
21
21
|
|
22
22
|
|
23
|
-
の部分を
|
23
|
+
の部分のアイキャッチ部分をいじりたいのですが、どうやら親テーマ内のfunctions.phpを触らないといけないようです。
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
上記以外のアイキャッチ表示部分(トップページの新着記事欄、ページ下のOverall Ranking欄、記事ページのタイトル横など)は自分でコードを見つけることができたので変更し、記事内最初の画像がアイキャッチとして表示されました。
|
28
|
-
|
29
|
-
た
|
25
|
+
直でいじってみたり、子テーマを親テーマの後から動かすようにして上書きしようとしてみましたがエラーが出てしまい修正できません。
|
30
26
|
|
31
27
|
|
32
28
|
|
@@ -34,17 +30,107 @@
|
|
34
30
|
|
35
31
|
|
36
32
|
|
37
|
-
###
|
33
|
+
### 該当のソースコード
|
34
|
+
|
35
|
+
↓↓↓親テーマ内のfunctions.phpの変更したい部分の1つです↓↓↓
|
38
36
|
|
39
37
|
|
40
38
|
|
39
|
+
```php
|
40
|
+
|
41
|
+
//////////////////////////////////////////////////
|
42
|
+
|
41
|
-
アイ
|
43
|
+
//新着記事ウィジェットアイテムのフォーマット変更(サムネイル追加)
|
44
|
+
|
45
|
+
//////////////////////////////////////////////////
|
46
|
+
|
47
|
+
class fit_recent_posts_widget extends wp_widget_recent_posts {
|
48
|
+
|
49
|
+
function widget($args, $instance) {
|
50
|
+
|
51
|
+
extract( $args );
|
52
|
+
|
53
|
+
$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title'], $instance, $this->id_base);
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
if( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
|
58
|
+
|
59
|
+
$number = 10;
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
$r = new WP_Query( apply_filters( 'widget_posts_args', array( 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true ) ) );
|
64
|
+
|
65
|
+
if( $r->have_posts() ) :
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
echo $before_widget;
|
70
|
+
|
71
|
+
if( $title ) echo $before_title . $title . $after_title; ?>
|
72
|
+
|
73
|
+
<ol class="imgListWidget">
|
74
|
+
|
75
|
+
<?php while( $r->have_posts() ) : $r->the_post(); ?>
|
76
|
+
|
77
|
+
<li class="imgListWidget__item">
|
78
|
+
|
79
|
+
<a class="imgListWidget__borderBox" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><span>
|
80
|
+
|
81
|
+
<?php if ( has_post_thumbnail()): ?>
|
82
|
+
|
83
|
+
<?php the_post_thumbnail('thumbnail'); ?>
|
84
|
+
|
85
|
+
<?php else: ?>
|
86
|
+
|
87
|
+
<img src="<?php echo get_template_directory_uri(); ?>/img/img_no_thumbnail.gif" alt="NO IMAGE">
|
88
|
+
|
89
|
+
<?php endif; ?>
|
90
|
+
|
91
|
+
</span></a>
|
92
|
+
|
93
|
+
<h3 class="imgListWidget__title">
|
94
|
+
|
95
|
+
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
|
96
|
+
|
97
|
+
<?php if( !empty( $instance['show_date'] )): ?><span class="post-date"><?php the_time('Y.m.d'); ?></span><?php endif; ?>
|
98
|
+
|
99
|
+
</h3>
|
100
|
+
|
101
|
+
</li>
|
102
|
+
|
103
|
+
<?php endwhile; ?>
|
104
|
+
|
105
|
+
</ol>
|
106
|
+
|
107
|
+
<?php
|
108
|
+
|
109
|
+
echo $after_widget;
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
wp_reset_postdata();
|
114
|
+
|
115
|
+
endif;
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
}
|
120
|
+
|
121
|
+
function fit_recent_widget_registration() {
|
122
|
+
|
123
|
+
unregister_widget('wp_widget_recent_posts'); register_widget('fit_recent_posts_widget');
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
add_action('widgets_init', 'fit_recent_widget_registration');
|
128
|
+
|
129
|
+
```
|
42
130
|
|
43
131
|
|
44
132
|
|
45
|
-
### 該当のソースコード
|
46
|
-
|
47
|
-
|
133
|
+
↓↓↓上記のアイキャッチに関する部分を下記のコードに変更したいです↓↓↓
|
48
134
|
|
49
135
|
|
50
136
|
|
@@ -64,44 +150,6 @@
|
|
64
150
|
|
65
151
|
|
66
152
|
|
67
|
-
記事内の一番目にある画像を取得するコードは「functions.php」に入力済です。↓↓↓
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
```php
|
72
|
-
|
73
|
-
function catch_that_image() {
|
74
|
-
|
75
|
-
global $post, $posts;
|
76
|
-
|
77
|
-
$first_img = '';
|
78
|
-
|
79
|
-
ob_start();
|
80
|
-
|
81
|
-
ob_end_clean();
|
82
|
-
|
83
|
-
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
|
84
|
-
|
85
|
-
$first_img = $matches [1] [0];
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
if(empty($first_img)){
|
90
|
-
|
91
|
-
// 記事内で画像がなかったときのためのデフォルト画像を指定
|
92
|
-
|
93
|
-
$first_img = "/images/default.jpg";
|
94
|
-
|
95
|
-
}
|
96
|
-
|
97
|
-
return $first_img;
|
98
|
-
|
99
|
-
}
|
100
|
-
|
101
|
-
```
|
102
|
-
|
103
|
-
|
104
|
-
|
105
153
|
### 補足情報(FW/ツールのバージョンなど)
|
106
154
|
|
107
155
|
|