質問編集履歴

1

2016/05/24 11:38

投稿

hirororo
hirororo

スコア72

test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,13 @@
4
4
 
5
5
  一昨日、こちらのサイトで質問させて頂いてから
6
6
 
7
- プログラムを完成することが出来ました。
7
+ プログラムの動作確認することが出来ました。
8
+
9
+
10
+
11
+ [Wordpress記事をユーザー登録を行った日から経過した日数に応じて可変させたい](https://teratail.com/questions/35643)
12
+
13
+
8
14
 
9
15
 
10
16
 
@@ -12,46 +18,44 @@
12
18
 
13
19
 
14
20
 
21
+
22
+
15
- プログラミング初心者ある塾のWordpressサイトを運営してい
23
+ 古い記事の順番ユーザー登録日数に応じ表示させたのでが、
16
-
17
-
18
-
19
- 取引先で期限付きでサイト作成を依頼され、
24
+
20
-
21
- 期限内に必ず達成させたいいう思い書かせ頂きます。
25
+ 下のソースだ人気記事の順番表示されいます。
22
-
23
-
24
-
25
-
26
-
27
- 早速なのですが、
26
+
28
-
29
-
30
-
31
- Wordpresサイトでphpとsqlでユーザー登録を行った日から
27
+
32
-
33
- 経過した日数に応じた数の記事を『古い順番』で閲覧できる
28
+
34
-
35
- プログラムを作るにはどう取り組めばいいでしょうか?
29
+
36
-
37
-
38
-
30
+
39
- ザー登録行っ日から経過した日数に応じた数記事を
31
+ ■コ入れて動作が確認できワードプレス内ソース
40
-
41
- 表示させるプログラムは完成しました。
32
+
42
-
43
-
44
-
45
- 以下がそのプログラムになります。
33
+
46
-
47
-
48
-
49
-
50
-
51
- ■考えてみたPHP文
52
34
 
53
35
  ```lang-php
54
36
 
37
+ <div id="popular_post_content" class="front-loop">
38
+
39
+
40
+
41
+ <h2><i class="fa fa-flag"></i> 人気のある記事</h2>
42
+
43
+ <div class="wrap">
44
+
45
+ <div class="front-loop-cont">
46
+
47
+ <?php
48
+
49
+ $i = 1;
50
+
51
+ if ( have_posts() ) :
52
+
53
+ // wp_reset_query();
54
+
55
+
56
+
57
+
58
+
55
59
  $current_user = wp_get_current_user();
56
60
 
57
61
 
@@ -60,6 +64,8 @@
60
64
 
61
65
 
62
66
 
67
+ //$time1 = date("Y/m/d H:i:s", strtotime('-1 day'));
68
+
63
69
 
64
70
 
65
71
  $time2 = strtotime(date('Y/m/d H:i:s'));
@@ -76,202 +82,166 @@
76
82
 
77
83
  $daydiff = floor($diff) *2;
78
84
 
85
+
86
+
87
+
88
+
89
+ $args=array(
90
+
91
+ 'meta_query'=>
92
+
93
+ array(
94
+
95
+ array( 'key'=>'bzb_show_toppage_flag',
96
+
97
+ 'compare' => 'NOT EXISTS'
98
+
99
+ ),
100
+
101
+ array( 'key'=>'bzb_show_toppage_flag',
102
+
103
+ 'value'=>'none',
104
+
105
+ 'compare'=>'!='
106
+
107
+ ),
108
+
109
+ 'relation'=>'OR'
110
+
111
+ ),
112
+
113
+ 'showposts'=>$daydiff,
114
+
115
+ 'meta_key'=>'views',
116
+
117
+ 'orderby'=>'meta_value_num',
118
+
119
+ 'order'=>'DESC'
120
+
121
+ );
122
+
123
+ query_posts($args);
124
+
125
+ // query_posts('showposts=5&meta_key=views&orderby=meta_value_num&order=DESC');
126
+
127
+ while ( have_posts() ) : the_post();
128
+
129
+
130
+
131
+ $cf = get_post_meta($post->ID);
132
+
133
+ $rank_class = 'popular_post_box rank-'.$i;
134
+
135
+ // print_r($cf);
136
+
137
+ ?>
138
+
79
139
  ```
80
140
 
81
141
 
82
142
 
143
+ そこで下のようなソースにしてみると
144
+
145
+ 記事が1ページだけ表示されてしまいました。
146
+
147
+
148
+
149
+
150
+
151
+ ■以下ワードプレス内のソース
152
+
153
+
154
+
155
+ ```lang-php
156
+
157
+ <div id="recent_post_content" class="front-loop">
158
+
159
+
160
+
161
+ <h2><i class="fa fa-clock-o"></i> 最近の投稿</h2>
162
+
163
+ <div class="wrap">
164
+
165
+ <div class="front-loop-cont">
166
+
167
+ <?php
168
+
169
+ $i = 1;
170
+
171
+
172
+
173
+ if ( have_posts() ) :
174
+
175
+
176
+
177
+ $current_user = wp_get_current_user();
178
+
179
+
180
+
181
+ $time1 = strtotime($current_user->user_registered);
182
+
183
+
184
+
185
+ $time2 = strtotime(date('Y/m/d H:i:s'));
186
+
187
+
188
+
189
+ $seconddiff = abs($time2 - $time1);
190
+
191
+
192
+
193
+ $diff = $seconddiff / (60*60*24);
194
+
195
+
196
+
197
+ $daydiff = floor($diff) *2;
198
+
199
+
200
+
201
+ query_posts('showposts=$daydiff');
202
+
203
+ while ( have_posts() ) : the_post();
204
+
205
+
206
+
207
+ $cf = get_post_meta($post->ID);
208
+
209
+ $recent_class = 'popular_post_box recent-'.$i;
210
+
211
+ ?>
212
+
213
+ ```
214
+
215
+
216
+
217
+ また、記事を古い順番で表示させたいので、
218
+
219
+
220
+
221
+ while ( have_posts() ) : the_post();の上に
222
+
223
+
224
+
225
+ query_posts($query_string. '&order=ASC');と
226
+
227
+ コードを入れたところ、記事の表示は順逆になりましたが
228
+
229
+ 登録日数にかかわらず記事が全て表示されてしまいました。
230
+
231
+
232
+
233
+
234
+
83
- 今現在の不明点は、
235
+ 今現在の不明点
84
-
85
-
86
-
236
+
237
+
238
+
87
- 記事の更新日時が古い順番で記事を表示させること
239
+ ・更新日時が古い順番で記事を表示させる方法
88
240
 
89
241
  ・完成したコードをどこに入れればいいか
90
242
 
91
243
 
92
244
 
93
- になります。
94
-
95
-
96
-
97
-
98
-
99
- ■コードを取り組みたい場所
100
-
101
- (以下、ワードプレス トップページの一部)
102
-
103
-
104
-
105
- ```lang-php
106
-
107
- <div id="recent_post_content" class="front-loop">
108
-
109
-
110
-
111
- <h2><i class="fa fa-clock-o"></i> 最近の投稿</h2>
112
-
113
- <div class="wrap">
114
-
115
- <div class="front-loop-cont">
116
-
117
- <?php
118
-
119
- $i = 1;
120
-
121
- if ( have_posts() ) :
122
-
123
- query_posts('showposts=5');
124
-
125
- while ( have_posts() ) : the_post();
126
-
127
-
128
-
129
- $cf = get_post_meta($post->ID);
130
-
131
- $recent_class = 'popular_post_box recent-'.$i;
132
-
133
- ?>
134
-
135
-
136
-
137
- <article id="post-<?php echo the_ID(); ?>" <?php post_class($recent_class); ?>>
138
-
139
- <a href="<?php the_permalink(); ?>" class="wrap-a"><?php if( get_the_post_thumbnail() ) { ?>
140
-
141
- <div class="post-thumbnail">
142
-
143
- <?php the_post_thumbnail(array(1200, 630, true)); ?>
144
-
145
- </div>
146
-
147
- <?php } else{ ?>
148
-
149
- <img src="http://placehold.jp/300x160.png">
150
-
151
- <?php } // get_the_post_thumbnail ?>
152
-
153
- <p class="p_category"><?php $cat = get_the_category(); $cat = $cat[0]; {
154
-
155
- echo $cat->cat_name;
156
-
157
- } ?></p>
158
-
159
- <h3><?php the_title(); ?></h3>
160
-
161
- <ul>
162
-
163
- <li class="twitter"></li>
164
-
165
- <li class="facebook"></li>
166
-
167
- <li class="googlePlus"></li>
168
-
169
- <li class="hatena"></li>
170
-
171
- </ul>
172
-
173
- <p class="p_date"><span class="date-y"><?php the_time('Y'); ?></span><span class="date-mj"><?php the_time('m/j'); ?></span></p></a>
174
-
175
- </article>
176
-
177
-
178
-
179
- <?php
180
-
181
- $i++;
182
-
183
- endwhile;
184
-
185
- endif;
186
-
187
- ?>
188
-
189
- ```
190
-
191
-
192
-
193
- ■試してみたこと1
194
-
195
-
196
-
197
- 完成したコードを取り組み、
198
-
199
- query_posts('showposts=5');をquery_posts('showposts=$daydiff');に変えました。
200
-
201
-
202
-
203
-
204
-
205
- ```lang-php
206
-
207
- <?php
208
-
209
- $i = 1;
210
-
211
- if ( have_posts() ) :
212
-
213
-
214
-
215
- $current_user = wp_get_current_user();
216
-
217
-
218
-
219
- $time1 = strtotime($current_user->user_registered);
220
-
221
-
222
-
223
-
224
-
225
- $time2 = strtotime(date('Y/m/d H:i:s'));
226
-
227
-
228
-
229
- $seconddiff = abs($time2 - $time1);
230
-
231
-
232
-
233
- $diff = $seconddiff / (60*60*24);
234
-
235
-
236
-
237
- $daydiff = floor($diff)*2 ;
238
-
239
-
240
-
241
-
242
-
243
- query_posts('showposts=$daydiff');
244
-
245
- while ( have_posts() ) : the_post();
246
-
247
-
248
-
249
- $cf = get_post_meta($post->ID);
250
-
251
- $recent_class = 'popular_post_box recent-'.$i;
252
-
253
- ?>
254
-
255
- ```
256
-
257
-
258
-
259
- ■試してみたこと2
260
-
261
- while ( have_posts() ) : the_post();の上に
262
-
263
-
264
-
265
- query_posts($query_string. '&order=ASC');と
266
-
267
- コードを入れたところ、記事の表示は順逆になりましたが
268
-
269
- 登録日数にかかわらず記事が全て表示されてしまいました。
270
-
271
-
272
-
273
-
274
-
275
245
 
276
246
 
277
247
  ■使っているワードプレステーマ
@@ -286,26 +256,34 @@
286
256
 
287
257
 
288
258
 
289
- ワードプレスフォーラム 「質問」古い記事を上にする方法はありますか?
290
-
291
- https://ja.forums.wordpress.org/topic/5325
259
+ [ワードプレスフォーラム 「質問」古い記事を上にする方法はありますか? ](https://ja.forums.wordpress.org/topic/5325)
292
-
293
-
294
-
295
- 【WordPress】Xeoryのテーマをちょこっとだけカスタマイズする!前編
260
+
296
-
261
+
262
+
263
+
264
+
297
- http://dyd.jp/blog003-wordpress/
265
+ [【WordPress】Xeoryのテーマをちょこっとだけカスタマイズする!前編](http://dyd.jp/blog003-wordpress/)
266
+
267
+
268
+
269
+
298
270
 
299
271
 
300
272
 
301
- 日本語Codex クラスリファレンス/WP User
302
-
303
- https://goo.gl/Iix2ZQ
273
+ [日本語Codex クラスリファレンス/WP User ](https://goo.gl/Iix2ZQ)
274
+
275
+
276
+
277
+
278
+
279
+
304
280
 
305
281
 
306
282
 
307
283
  おかげさまでようやく完成に近づくことができました。
308
284
 
285
+
286
+
309
287
  またご教授して頂ければ幸いです。
310
288
 
311
289