回答編集履歴

2

typo

2024/03/31 07:56

投稿

Eggpan
Eggpan

スコア2797

test CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  #### 追記
9
9
  コードの例としては下記のような感じになります。
10
- 抽出条件適宜調整してください。
10
+ 抽出条件適宜調整してください。
11
11
  ```php
12
12
  <?php get_header() ?>
13
13
 

1

コード例の追記

2024/03/31 03:56

投稿

Eggpan
Eggpan

スコア2797

test CHANGED
@@ -5,3 +5,32 @@
5
5
 
6
6
  メインループと別に記事データを取得するには、 `get_posts()` を利用します。
7
7
 
8
+ #### 追記
9
+ コードの例としては下記のような感じになります。
10
+ 抽出条件が適宜調整してください。
11
+ ```php
12
+ <?php get_header() ?>
13
+
14
+ <!-- URLに応じた、single.phpが検出しているpost情報の表示 -->
15
+ <article>
16
+ <h1><?php the_title() ?></h1>
17
+ <div><?php the_content() ?></div>
18
+ </article>
19
+
20
+ <!-- 他のPOSTを別途5件ランダム表示 -->
21
+ <h3>other posts</h3>
22
+ <?php
23
+ $args = [
24
+ 'post_type' => 'post',
25
+ 'posts_per_page' => 5,
26
+ 'orderby' => 'rand',
27
+ 'post__not_in' => [get_the_ID()],
28
+ ];
29
+ foreach(get_posts($args) as $post): ?>
30
+ <article>
31
+ <p>title: <?php echo $post->post_title ?></p>
32
+ </article>
33
+ <?php endforeach; ?>
34
+
35
+ <?php get_footer() ?>
36
+ ```