質問編集履歴

2

書式の改善

2017/01/29 07:42

投稿

alesta
alesta

スコア16

test CHANGED
File without changes
test CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  ###発生している問題
10
10
 
11
- 画像サイズをfunction.phpやcssで指定しても、インラインスタイルの影響で反映されません。そして、コード内にstyle部分が見つからないのです。
11
+ 画像サイズをcssで指定しても、インラインスタイルの影響で反映されません。そして、ページコード内にstyle部分が見つからないのです。
12
12
 
13
13
 
14
14
 
@@ -36,11 +36,11 @@
36
36
 
37
37
  ```
38
38
 
39
-
39
+ こちらはsingle.phpです。
40
40
 
41
41
  ###試したこと
42
42
 
43
- function.phpやcssでclass名を付けてサイズを指定したがインラインスタイルのために反映されない。コードをいじってみたが画像まで消えてしまう。
43
+ cssでclass名を付けてサイズを指定したがインラインスタイルの方が強いために反映されない。ページコードをいじってみたが画像まで消えてしまう。
44
44
 
45
45
  ```php
46
46
 
@@ -48,11 +48,11 @@
48
48
 
49
49
  ```
50
50
 
51
- このあたりにwidthやheightが記載されているので、intvalについても調べてみたのですがイマイチわかりませんでした。
51
+ single.phpのこのあたりにwidthやheightが記載されているので、intvalについても調べてみたのですがイマイチわかりませんでした。
52
-
53
-
54
-
52
+
53
+
54
+
55
- ※上記のsingle.phpのコードを変更しても反映されないのでfunction.phpのコードにもサムネイルの情報がありましたので追記しました。
55
+ ※上記のsingle.phpのコードを変更しても反映されないのでfunction.phpにもサムネイルの情報がありましたのでそちらの可能性かと思いコードを追記しました。
56
56
 
57
57
  ###補足情報(言語/FW/ツール等のバージョンなど)
58
58
 

1

該当コード情報の追加

2017/01/29 07:42

投稿

alesta
alesta

スコア16

test CHANGED
File without changes
test CHANGED
@@ -50,6 +50,10 @@
50
50
 
51
51
  このあたりにwidthやheightが記載されているので、intvalについても調べてみたのですがイマイチわかりませんでした。
52
52
 
53
+
54
+
55
+ ※上記のsingle.phpのコードを変更しても反映されないのでfunction.phpのコードにもサムネイルの情報がありましたので追記しました。
56
+
53
57
  ###補足情報(言語/FW/ツール等のバージョンなど)
54
58
 
55
59
  より詳細な情報
@@ -59,3 +63,159 @@
59
63
  theme:chocolate
60
64
 
61
65
  php
66
+
67
+
68
+
69
+ 以下にfunction.phpのコードを追加します。
70
+
71
+ ```php
72
+
73
+ // 2.1.1 - post-thumbnails
74
+
75
+ add_theme_support( 'post-thumbnails' );
76
+
77
+
78
+
79
+ // 2.1.1.0 - thumbnail image
80
+
81
+ $thumbnail_crop_x = ( ! empty( $options['thumbnail_crop_x'] ) ) ? esc_attr( $options['thumbnail_crop_x'] ) : 'center';
82
+
83
+ $thumbnail_crop_y = ( ! empty( $options['thumbnail_crop_y'] ) ) ? esc_attr( $options['thumbnail_crop_y'] ) : 'center';
84
+
85
+ set_post_thumbnail_size( 300, 300, array( $thumbnail_crop_x, $thumbnail_crop_y ) );
86
+
87
+
88
+
89
+ // 2.1.1.1 - Registers a new image size (post_thumbnails, single-post-thumbnail)
90
+
91
+ $featured_size_w = ( ! empty( $options['featured_size_w'] ) ) ? absint( $options['featured_size_w'] ) : 700;
92
+
93
+ $featured_size_h = ( ! empty( $options['featured_size_h'] ) ) ? absint( $options['featured_size_h'] ) : 350;
94
+
95
+ $featured_crop = false;
96
+
97
+
98
+
99
+ if ( ! empty( $options['featured_crop'] ) ) {
100
+
101
+ if ( $options['featured_crop'] == 'crop' ) {
102
+
103
+ $featured_crop_x = ( ! empty( $options['featured_crop_x'] ) ) ? esc_attr( $options['featured_crop_x'] ) : 'center';
104
+
105
+ $featured_crop_y = ( ! empty( $options['featured_crop_y'] ) ) ? esc_attr( $options['featured_crop_y'] ) : 'center';
106
+
107
+ $featured_crop = array( $featured_crop_x, $featured_crop_y );
108
+
109
+ } else {
110
+
111
+ $featured_crop = false;
112
+
113
+ }
114
+
115
+ }
116
+
117
+
118
+
119
+ // 2.1.1.2 - Changed the name to "single-post-thumbnail" from "post_thumbnail"
120
+
121
+ add_image_size( 'post_thumbnail', $featured_size_w, $featured_size_h, $featured_crop );
122
+
123
+ add_image_size( 'single-post-thumbnail', $featured_size_w, $featured_size_h, $featured_crop );
124
+
125
+
126
+
127
+ // 2.1.1.3 - Registers a new image size of home page (home-post-thumbnail)
128
+
129
+ if ( ! empty( $options['show_featured_home'] ) ) {
130
+
131
+ $featured_home_size_w = ( ! empty( $options['featured_home_size_w'] ) ) ? absint( $options['featured_home_size_w'] ) : 700;
132
+
133
+ $featured_home_size_h = ( ! empty( $options['featured_home_size_h'] ) ) ? absint( $options['featured_home_size_h'] ) : 350;
134
+
135
+ $featured_home_crop = true;
136
+
137
+
138
+
139
+ if ( ! empty( $options['featured_home_crop'] ) ) {
140
+
141
+ if ( $options['featured_home_crop'] == 'crop' ) {
142
+
143
+ $featured_home_crop_x = ( ! empty( $options['featured_home_crop_x'] ) ) ? esc_attr( $options['featured_home_crop_x'] ) : 'center';
144
+
145
+ $featured_home_crop_y = ( ! empty( $options['featured_home_crop_y'] ) ) ? esc_attr( $options['featured_home_crop_y'] ) : 'center';
146
+
147
+ $featured_home_crop = array( $featured_home_crop_x, $featured_home_crop_y );
148
+
149
+ } else {
150
+
151
+ $featured_home_crop = false;
152
+
153
+ }
154
+
155
+ }
156
+
157
+
158
+
159
+ /* ----------------------------------------------
160
+
161
+ * 2.1.1 - post-thumbnails
162
+
163
+ * Image size square
164
+
165
+ * --------------------------------------------*/
166
+
167
+
168
+
169
+ if ( ! function_exists( 'chocolat_post_thumbnail' ) ) :
170
+
171
+ function chocolat_post_thumbnail() {
172
+
173
+ $img_size = 300;
174
+
175
+ if ( has_post_thumbnail() ) {
176
+
177
+ the_post_thumbnail( 'thumbnail', array( 'alt' => the_title_attribute( 'echo=0' ) ) );
178
+
179
+ } else {
180
+
181
+ global $post;
182
+
183
+ $str = $post->post_content;
184
+
185
+ $searchPattern = '/<img.*?src=(["\'])(.+?)\1.*?>/i';
186
+
187
+ $noimage_url = get_template_directory_uri() .'/img/common/thumbnail.png';
188
+
189
+ $img_class = '';
190
+
191
+
192
+
193
+ if ( preg_match( $searchPattern, $str, $imgurl ) ) {
194
+
195
+ $noimage_url = $imgurl[2];
196
+
197
+ $img_class = ' no-thumbnail-image';
198
+
199
+ } else {
200
+
201
+ $options = chocolat_get_option();
202
+
203
+ if ( ! empty( $options['no_image_url'] ) ) {
204
+
205
+ $noimage_url = $options['no_image_url'];
206
+
207
+ }
208
+
209
+ }
210
+
211
+ echo '<img src="'.esc_url( $noimage_url ).'" class="attachment-thumbnail wp-post-image'.esc_attr( $img_class ).'" alt="'.the_title_attribute( 'echo=0' ).'" width="'.absint( $img_size ).'" height="'.absint( $img_size ).'" />';
212
+
213
+ }
214
+
215
+ }
216
+
217
+ endif;
218
+
219
+
220
+
221
+ ```