teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

追記

2019/05/15 12:41

投稿

Capeta
Capeta

スコア11

title CHANGED
File without changes
body CHANGED
@@ -60,4 +60,36 @@
60
60
  //定型文を表示
61
61
  </p>
62
62
 
63
+ ```
64
+
65
+ 皆様のおかげでとりあえず動くようにはなりました。
66
+ 今回はposttypeが2つしかなかったので以下でも問題なさそうです。
67
+
68
+ ### 回答反映例
69
+
70
+ ```php
71
+
72
+ <?php
73
+ $args = array(
74
+ 'post_type' => array('post','sample'),
75
+ );
76
+ $wp_query = new WP_Query( $args ); ?>
77
+ <?php
78
+ if ( $wp_query->have_posts() ) {
79
+ while ( $wp_query->have_posts() ){
80
+ $wp_query->the_post();
81
+ ?>
82
+ <?php $posttype = get_post_type( get_the_ID() );
83
+ if ( $posttype == 'post' ) {
84
+ echo '<h2>'
85
+ . get_the_title() .
86
+ '</h2>';
87
+ } else {
88
+ echo '<h2 class="hoge">' . get_the_title() . '</h2><p> //定型文を表示 </p>';
89
+ } ?>
90
+ <?php
91
+ }
92
+ }
93
+ ?>
94
+
63
95
  ```