質問編集履歴
1
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,34 +1,37 @@
|
|
1
1
|
はじめまして!
|
2
2
|
|
3
3
|
一昨日、こちらのサイトで質問させて頂いてから
|
4
|
-
プログラムを
|
4
|
+
プログラムの動作を確認することが出来ました。
|
5
5
|
|
6
|
+
[Wordpress記事をユーザー登録を行った日から経過した日数に応じて可変させたい](https://teratail.com/questions/35643)
|
7
|
+
|
8
|
+
|
6
9
|
まだ一点問題があるため、改めて質問させてください。
|
7
10
|
|
8
|
-
プログラミング初心者である塾のWordpressサイトを運営しています。
|
9
11
|
|
10
|
-
|
12
|
+
古い記事の順番でユーザー登録日数に応じて表示させたいのですが、
|
11
|
-
|
13
|
+
下のソースだと人気記事の順番で表示されてしまいます。
|
12
14
|
|
13
15
|
|
14
|
-
|
16
|
+
■コードを入れて動作が確認できたワードプレス内のソース
|
15
17
|
|
18
|
+
```lang-php
|
16
|
-
|
19
|
+
<div id="popular_post_content" class="front-loop">
|
17
|
-
経過した日数に応じた数の記事を『古い順番』で閲覧できる
|
18
|
-
プログラムを作るにはどう取り組めばいいでしょうか?
|
19
20
|
|
21
|
+
<h2><i class="fa fa-flag"></i> 人気のある記事</h2>
|
22
|
+
<div class="wrap">
|
23
|
+
<div class="front-loop-cont">
|
24
|
+
<?php
|
25
|
+
$i = 1;
|
26
|
+
if ( have_posts() ) :
|
20
|
-
|
27
|
+
// wp_reset_query();
|
21
|
-
表示させるプログラムは完成しました。
|
22
28
|
|
23
|
-
以下がそのプログラムになります。
|
24
29
|
|
25
|
-
|
26
|
-
■考えてみたPHP文
|
27
|
-
```lang-php
|
28
30
|
$current_user = wp_get_current_user();
|
29
31
|
|
30
32
|
$time1 = strtotime($current_user->user_registered);
|
31
33
|
|
34
|
+
//$time1 = date("Y/m/d H:i:s", strtotime('-1 day'));
|
32
35
|
|
33
36
|
$time2 = strtotime(date('Y/m/d H:i:s'));
|
34
37
|
|
@@ -37,97 +40,74 @@
|
|
37
40
|
$diff = $seconddiff / (60*60*24);
|
38
41
|
|
39
42
|
$daydiff = floor($diff) *2;
|
40
|
-
```
|
41
43
|
|
42
|
-
今現在の不明点は、
|
43
44
|
|
45
|
+
$args=array(
|
44
|
-
|
46
|
+
'meta_query'=>
|
47
|
+
array(
|
48
|
+
array( 'key'=>'bzb_show_toppage_flag',
|
49
|
+
'compare' => 'NOT EXISTS'
|
50
|
+
),
|
51
|
+
array( 'key'=>'bzb_show_toppage_flag',
|
52
|
+
'value'=>'none',
|
53
|
+
'compare'=>'!='
|
54
|
+
),
|
55
|
+
'relation'=>'OR'
|
56
|
+
),
|
57
|
+
'showposts'=>$daydiff,
|
58
|
+
'meta_key'=>'views',
|
59
|
+
'orderby'=>'meta_value_num',
|
60
|
+
'order'=>'DESC'
|
61
|
+
);
|
45
|
-
|
62
|
+
query_posts($args);
|
63
|
+
// query_posts('showposts=5&meta_key=views&orderby=meta_value_num&order=DESC');
|
64
|
+
while ( have_posts() ) : the_post();
|
46
65
|
|
66
|
+
$cf = get_post_meta($post->ID);
|
67
|
+
$rank_class = 'popular_post_box rank-'.$i;
|
68
|
+
// print_r($cf);
|
47
|
-
|
69
|
+
?>
|
70
|
+
```
|
48
71
|
|
72
|
+
そこで下のようなソースにしてみると
|
73
|
+
記事が1ページだけ表示されてしまいました。
|
49
74
|
|
50
|
-
■コードを取り組みたい場所
|
51
|
-
(以下、ワードプレス トップページの一部)
|
52
75
|
|
76
|
+
■以下ワードプレス内のソース
|
77
|
+
|
53
78
|
```lang-php
|
54
79
|
<div id="recent_post_content" class="front-loop">
|
55
80
|
|
56
81
|
<h2><i class="fa fa-clock-o"></i> 最近の投稿</h2>
|
57
82
|
<div class="wrap">
|
58
|
-
|
83
|
+
<div class="front-loop-cont">
|
59
84
|
<?php
|
60
|
-
|
85
|
+
$i = 1;
|
61
|
-
if ( have_posts() ) :
|
62
|
-
query_posts('showposts=5');
|
63
|
-
while ( have_posts() ) : the_post();
|
64
86
|
|
65
|
-
|
87
|
+
if ( have_posts() ) :
|
66
|
-
$recent_class = 'popular_post_box recent-'.$i;
|
67
|
-
?>
|
68
88
|
|
69
|
-
<article id="post-<?php echo the_ID(); ?>" <?php post_class($recent_class); ?>>
|
70
|
-
<a href="<?php the_permalink(); ?>" class="wrap-a"><?php if( get_the_post_thumbnail() ) { ?>
|
71
|
-
<div class="post-thumbnail">
|
72
|
-
<?php the_post_thumbnail(array(1200, 630, true)); ?>
|
73
|
-
</div>
|
74
|
-
<?php } else{ ?>
|
75
|
-
<img src="http://placehold.jp/300x160.png">
|
76
|
-
<?php } // get_the_post_thumbnail ?>
|
77
|
-
<p class="p_category"><?php $cat = get_the_category(); $cat = $cat[0]; {
|
78
|
-
echo $cat->cat_name;
|
79
|
-
} ?></p>
|
80
|
-
<h3><?php the_title(); ?></h3>
|
81
|
-
<ul>
|
82
|
-
<li class="twitter"></li>
|
83
|
-
<li class="facebook"></li>
|
84
|
-
<li class="googlePlus"></li>
|
85
|
-
<li class="hatena"></li>
|
86
|
-
</ul>
|
87
|
-
<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>
|
88
|
-
</article>
|
89
|
-
|
90
|
-
<?php
|
91
|
-
$i++;
|
92
|
-
endwhile;
|
93
|
-
endif;
|
94
|
-
?>
|
95
|
-
```
|
96
|
-
|
97
|
-
■試してみたこと1
|
98
|
-
|
99
|
-
完成したコードを取り組み、
|
100
|
-
query_posts('showposts=5');をquery_posts('showposts=$daydiff');に変えました。
|
101
|
-
|
102
|
-
|
103
|
-
```lang-php
|
104
|
-
<?php
|
105
|
-
$i = 1;
|
106
|
-
if ( have_posts() ) :
|
107
|
-
|
108
89
|
$current_user = wp_get_current_user();
|
109
90
|
|
110
91
|
$time1 = strtotime($current_user->user_registered);
|
111
92
|
|
112
|
-
|
113
93
|
$time2 = strtotime(date('Y/m/d H:i:s'));
|
114
94
|
|
115
95
|
$seconddiff = abs($time2 - $time1);
|
116
96
|
|
117
97
|
$diff = $seconddiff / (60*60*24);
|
118
98
|
|
119
|
-
$daydiff = floor($diff)*2
|
99
|
+
$daydiff = floor($diff) *2;
|
120
100
|
|
101
|
+
query_posts('showposts=$daydiff');
|
102
|
+
while ( have_posts() ) : the_post();
|
121
103
|
|
122
|
-
query_posts('showposts=$daydiff');
|
123
|
-
while ( have_posts() ) : the_post();
|
124
|
-
|
125
|
-
|
104
|
+
$cf = get_post_meta($post->ID);
|
126
|
-
|
105
|
+
$recent_class = 'popular_post_box recent-'.$i;
|
127
106
|
?>
|
128
107
|
```
|
129
108
|
|
130
|
-
|
109
|
+
また、記事を古い順番で表示させたいので、
|
110
|
+
|
131
111
|
while ( have_posts() ) : the_post();の上に
|
132
112
|
|
133
113
|
query_posts($query_string. '&order=ASC');と
|
@@ -135,23 +115,32 @@
|
|
135
115
|
登録日数にかかわらず記事が全て表示されてしまいました。
|
136
116
|
|
137
117
|
|
118
|
+
■今現在の不明点
|
138
119
|
|
120
|
+
・更新日時が古い順番で記事を表示させる方法
|
121
|
+
・完成したコードをどこに入れればいいか
|
122
|
+
|
123
|
+
|
139
124
|
■使っているワードプレステーマ
|
140
125
|
XEORY EXTENSION
|
141
126
|
|
142
127
|
|
143
128
|
■参考サイト
|
144
129
|
|
145
|
-
ワードプレスフォーラム 「質問」古い記事を上にする方法はありますか?
|
146
|
-
https://ja.forums.wordpress.org/topic/5325
|
130
|
+
[ワードプレスフォーラム 「質問」古い記事を上にする方法はありますか? ](https://ja.forums.wordpress.org/topic/5325)
|
147
131
|
|
148
|
-
|
132
|
+
|
149
|
-
http://dyd.jp/blog003-wordpress/
|
133
|
+
[【WordPress】Xeoryのテーマをちょこっとだけカスタマイズする!前編](http://dyd.jp/blog003-wordpress/)
|
134
|
+
|
135
|
+
|
150
136
|
|
151
|
-
日本語Codex クラスリファレンス/WP User
|
152
|
-
https://goo.gl/Iix2ZQ
|
137
|
+
[日本語Codex クラスリファレンス/WP User ](https://goo.gl/Iix2ZQ)
|
153
138
|
|
139
|
+
|
140
|
+
|
141
|
+
|
154
142
|
おかげさまでようやく完成に近づくことができました。
|
143
|
+
|
155
144
|
またご教授して頂ければ幸いです。
|
156
145
|
|
157
146
|
よろしくお願いいたします。
|