質問編集履歴

2

正解のコードを追加

2016/12/14 06:13

投稿

cues
cues

スコア23

test CHANGED
File without changes
test CHANGED
@@ -70,57 +70,9 @@
70
70
 
71
71
 
72
72
 
73
- お教えいただいた内容をもとに修正いたまし
73
+ 動作したコードはこちら
74
74
 
75
75
  ```php
76
-
77
- <?php get_header(); ?>
78
-
79
- <div class="title">
80
-
81
- <h1><span><?php echo esc_html(get_post_type_object(get_post_type())->label); ?></span></h1>
82
-
83
- </div>
84
-
85
-
86
-
87
- <div id="wrap">
88
-
89
- <main class="column">
90
-
91
- <?php if (have_posts()) : ?>
92
-
93
- <?php while (have_posts()) : the_post(); ?>
94
-
95
- <article>
96
-
97
- <h3><?php the_title(); ?></h3>
98
-
99
- <div>
100
-
101
- <span><?php the_time('Y.m.d'); ?></span>
102
-
103
- <span><?php echo get_the_term_list($post->ID, 'faq-cat'); ?></span>
104
-
105
- <p><?php remove_filter ('the_content', 'wpautop'); ?><?php the_content(); ?></p>
106
-
107
- </div>
108
-
109
- </article>
110
-
111
-
112
-
113
- <?php endwhile; ?>
114
-
115
- <?php else : ?>
116
-
117
- <p>ただいま準備中です。しばらくお待ちください。</p>
118
-
119
- <?php endif; ?>
120
-
121
- <!--関連記事-->
122
-
123
- <h3>関連記事</h3>
124
76
 
125
77
  <?php
126
78
 
@@ -128,19 +80,15 @@
128
80
 
129
81
  //$term = array_shift(get_the_terms($post->ID, 'faq'));
130
82
 
131
- $term = array_shift(get_the_terms($post->ID, 'faq_cat')); // タクソノミー名を指定する
83
+ $term = array_shift(get_the_terms($post->ID, 'faq-cat')); // タクソノミー名を指定する
132
84
 
133
85
  $args = array(
134
86
 
135
- 'numberposts' => 8, //8件表示
87
+ 'numberposts' => 8, //8件表示(デフォルトは5件)
136
-
137
- //'post_type' => 'faq, //カスタム投稿タイプ名
138
88
 
139
89
  'post_type' => 'faq', //カスタム投稿タイプ名
140
90
 
141
- //'taxonomy' => 'faq-cat', //タクソノミー名
142
-
143
- 'taxonomy' => 'faq_cat', //タクソノミー名
91
+ 'taxonomy' => 'faq-cat', //タクソノミー名 ←ここが追加
144
92
 
145
93
  'term' => $term->slug, //ターム名
146
94
 
@@ -170,16 +118,4 @@
170
118
 
171
119
 
172
120
 
173
- </main>
174
-
175
-
176
-
177
- <?php get_sidebar(); ?>
178
-
179
- </div>
180
-
181
- <?php get_footer(); ?>
182
-
183
-
184
-
185
121
  ```

1

修正後の内容を掲載

2016/12/14 06:13

投稿

cues
cues

スコア23

test CHANGED
File without changes
test CHANGED
@@ -63,3 +63,123 @@
63
63
  おわかりでしたら、お力貸していただければ幸いです。
64
64
 
65
65
  宜しくお願いいたします。
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+ ↓お教えいただいた内容をもとに修正いたしました。
74
+
75
+ ```php
76
+
77
+ <?php get_header(); ?>
78
+
79
+ <div class="title">
80
+
81
+ <h1><span><?php echo esc_html(get_post_type_object(get_post_type())->label); ?></span></h1>
82
+
83
+ </div>
84
+
85
+
86
+
87
+ <div id="wrap">
88
+
89
+ <main class="column">
90
+
91
+ <?php if (have_posts()) : ?>
92
+
93
+ <?php while (have_posts()) : the_post(); ?>
94
+
95
+ <article>
96
+
97
+ <h3><?php the_title(); ?></h3>
98
+
99
+ <div>
100
+
101
+ <span><?php the_time('Y.m.d'); ?></span>
102
+
103
+ <span><?php echo get_the_term_list($post->ID, 'faq-cat'); ?></span>
104
+
105
+ <p><?php remove_filter ('the_content', 'wpautop'); ?><?php the_content(); ?></p>
106
+
107
+ </div>
108
+
109
+ </article>
110
+
111
+
112
+
113
+ <?php endwhile; ?>
114
+
115
+ <?php else : ?>
116
+
117
+ <p>ただいま準備中です。しばらくお待ちください。</p>
118
+
119
+ <?php endif; ?>
120
+
121
+ <!--関連記事-->
122
+
123
+ <h3>関連記事</h3>
124
+
125
+ <?php
126
+
127
+ global $post;
128
+
129
+ //$term = array_shift(get_the_terms($post->ID, 'faq'));
130
+
131
+ $term = array_shift(get_the_terms($post->ID, 'faq_cat')); // タクソノミー名を指定する
132
+
133
+ $args = array(
134
+
135
+ 'numberposts' => 8, //8件表示
136
+
137
+ //'post_type' => 'faq, //カスタム投稿タイプ名
138
+
139
+ 'post_type' => 'faq', //カスタム投稿タイプ名
140
+
141
+ //'taxonomy' => 'faq-cat', //タクソノミー名
142
+
143
+ 'taxonomy' => 'faq_cat', //タクソノミー名
144
+
145
+ 'term' => $term->slug, //ターム名
146
+
147
+ 'orderby' => 'rand', //ランダム表示
148
+
149
+ 'post__not_in' => array($post->ID) //表示中の記事を除外
150
+
151
+ );
152
+
153
+ ?>
154
+
155
+ <?php $myPosts = get_posts($args); if($myPosts) : ?>
156
+
157
+ <?php foreach($myPosts as $post) : setup_postdata($post); ?>
158
+
159
+ <p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
160
+
161
+ <?php endforeach; ?>
162
+
163
+ <?php else : ?>
164
+
165
+ <p>関連アイテムはまだありません。</p>
166
+
167
+ <?php endif; wp_reset_postdata(); ?>
168
+
169
+ <!--ここまで-->
170
+
171
+
172
+
173
+ </main>
174
+
175
+
176
+
177
+ <?php get_sidebar(); ?>
178
+
179
+ </div>
180
+
181
+ <?php get_footer(); ?>
182
+
183
+
184
+
185
+ ```