質問編集履歴
3
間違えていたので再度修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
- メインループでnewsの個別記事を表示
|
8
8
|
- productsをwp-queryで表示
|
9
9
|
●うまく行かない
|
10
|
-
productsをwp-queryで記述した途端、newsの個別記事がproductsの
|
10
|
+
productsをwp-queryで記述した途端、newsの個別記事がproductsの全記事に切り替わってしまった。
|
11
11
|
|
12
12
|
【Case2】single-○○.phpで個別データと同時にその一覧を下に表示
|
13
13
|
single-news.php内で個別記事を表示させたその下に、一覧も表示させたい。
|
@@ -15,7 +15,7 @@
|
|
15
15
|
- メインループでnewsの個別記事を表示
|
16
16
|
- newsをwp-queryで表示
|
17
17
|
●うまく行かない
|
18
|
-
newsをwp-queryで記述した途端、newsの個別記事がその
|
18
|
+
newsをwp-queryで記述した途端、newsの個別記事がその全記事に切り替わってしまった。
|
19
19
|
|
20
20
|
```php
|
21
21
|
<?php
|
@@ -32,7 +32,7 @@
|
|
32
32
|
$wp_query = new WP_Query($args);
|
33
33
|
|
34
34
|
// newsのメインループ
|
35
|
-
// 本来ならnewsの個別記事が表示されるがwp_queryで設定したカスタム投稿の
|
35
|
+
// 本来ならnewsの個別記事が表示されるがwp_queryで設定したカスタム投稿の全記事に切り替わってしまう
|
36
36
|
if( have_posts() ):
|
37
37
|
while( have_posts() ) : the_post();
|
38
38
|
the_content();
|
2
コード部分補足しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,10 +32,11 @@
|
|
32
32
|
$wp_query = new WP_Query($args);
|
33
33
|
|
34
34
|
// newsのメインループ
|
35
|
+
// 本来ならnewsの個別記事が表示されるがwp_queryで設定したカスタム投稿の最新記事に切り替わってしまう
|
35
|
-
|
36
|
+
if( have_posts() ):
|
36
|
-
|
37
|
+
while( have_posts() ) : the_post();
|
37
38
|
the_content();
|
38
|
-
|
39
|
+
endwhile;
|
39
|
-
|
40
|
+
endif;
|
40
41
|
?>
|
41
42
|
```
|
1
コード一部修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -29,9 +29,9 @@
|
|
29
29
|
'paged' => $paged,
|
30
30
|
'posts_per_page' => -1, // 表示する数
|
31
31
|
];
|
32
|
+
$wp_query = new WP_Query($args);
|
32
33
|
|
33
34
|
// newsのメインループ
|
34
|
-
$wp_query = new WP_Query($args);
|
35
35
|
if( have_posts() ):
|
36
36
|
while( have_posts() ) : the_post();
|
37
37
|
the_content();
|