質問編集履歴

4

画像追加

2019/07/16 10:13

投稿

makoto-n
makoto-n

スコア436

test CHANGED
File without changes
test CHANGED
@@ -241,3 +241,11 @@
241
241
  ```
242
242
 
243
243
  `if ( get_post_meta($post->ID, 'img', true) )`がtrueになりません。
244
+
245
+
246
+
247
+ ---
248
+
249
+ 表示箇所のスクリーンショット
250
+
251
+ ![イメージ説明](8e4c560ec39ff1f3b4ad31f9df021409.png)

3

追記

2019/07/16 10:13

投稿

makoto-n
makoto-n

スコア436

test CHANGED
File without changes
test CHANGED
@@ -211,3 +211,33 @@
211
211
  <?php else: endif; ?>
212
212
 
213
213
  ```
214
+
215
+ functions.php
216
+
217
+ ```php
218
+
219
+ // small_thum_chk
220
+
221
+ function small_thum_chk() {
222
+
223
+ if ( get_post_meta($post->ID, 'img', true) ){
224
+
225
+ $thumb = '<img src='.get_post_meta($post->ID, 'img', true).'>';
226
+
227
+ } elseif ( has_post_thumbnail() ) {
228
+
229
+ $thumb = the_post_thumbnail( 'small_thumbnail', array('title' => get_the_title()) );
230
+
231
+ } else {
232
+
233
+ $thumb = '<img src="https://placehold.jp/eee/aaa/64x64.jpg?text=no-img">';
234
+
235
+ }
236
+
237
+ echo $thumb;
238
+
239
+ }
240
+
241
+ ```
242
+
243
+ `if ( get_post_meta($post->ID, 'img', true) )`がtrueになりません。

2

追記

2019/07/16 09:58

投稿

makoto-n
makoto-n

スコア436

test CHANGED
File without changes
test CHANGED
@@ -167,3 +167,47 @@
167
167
  のみ読み込んでいます。
168
168
 
169
169
  imgのカスタムフィールドは記述しています。
170
+
171
+
172
+
173
+
174
+
175
+ 追記
176
+
177
+ ---
178
+
179
+ ```php
180
+
181
+ <?php if (have_posts()) : ?>
182
+
183
+ <section class="sidebar_area">
184
+
185
+ <p>最近の投稿</p>
186
+
187
+ <?php global $post;
188
+
189
+ $args = array(
190
+
191
+ 'posts_per_page' => 4
192
+
193
+ );
194
+
195
+ $myposts = get_posts( $args );
196
+
197
+ foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
198
+
199
+ <div class="sidebar_post clearfix">
200
+
201
+ <a href="<?php the_permalink() ?>" class="float-left"><?php small_thum_chk(); ?></a>
202
+
203
+ <h4 class="float-left"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4>
204
+
205
+ </div>
206
+
207
+ <?php endforeach; ?>
208
+
209
+ </section>
210
+
211
+ <?php else: endif; ?>
212
+
213
+ ```

1

追記

2019/07/16 09:56

投稿

makoto-n
makoto-n

スコア436

test CHANGED
File without changes
test CHANGED
@@ -113,3 +113,57 @@
113
113
 
114
114
 
115
115
  ```
116
+
117
+
118
+
119
+ ---
120
+
121
+ 修正テキスト
122
+
123
+ functions.phpに記載
124
+
125
+ ```php
126
+
127
+ // small_thum_chk
128
+
129
+ function small_thum_chk() {
130
+
131
+ if ( get_post_meta($post->ID, 'img', true) ){
132
+
133
+ $thumb = '<img src='.get_post_meta($post->ID, 'img', true).'>';
134
+
135
+ } elseif ( has_post_thumbnail() ) {
136
+
137
+ $thumb = the_post_thumbnail( 'small_thumbnail', array('title' => get_the_title()) );
138
+
139
+ } else {
140
+
141
+ $thumb = '<img src="https://placehold.jp/eee/aaa/64x64.jpg?text=no-img">';
142
+
143
+ }
144
+
145
+ echo $thumb;
146
+
147
+ }
148
+
149
+ ```
150
+
151
+ small_thum_chk()を呼び出した際にのみカスタムフィールドに記載されているURLを記述したimgタグを挿入できるようにしたいです。
152
+
153
+ 発生している事象ですが,
154
+
155
+ `if ( get_post_meta($post->ID, 'img', true) )`を認識せず、
156
+
157
+ ```php
158
+
159
+ elseif ( has_post_thumbnail() ) {
160
+
161
+ $thumb = the_post_thumbnail( 'small_thumbnail', array('title' => get_the_title()) );
162
+
163
+ }
164
+
165
+ ```
166
+
167
+ のみ読み込んでいます。
168
+
169
+ imgのカスタムフィールドは記述しています。