質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Q&A

1回答

1399閲覧

カスタム投稿タイプの情報が生成されない(Wordpress)

Nemuu

総合スコア14

WordPress

WordPressは、PHPで開発されているオープンソースのブログソフトウェアです。データベース管理システムにはMySQLを用いています。フリーのブログソフトウェアの中では最も人気が高く、PHPとHTMLを使って簡単にテンプレートをカスタマイズすることができます。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

0グッド

0クリップ

投稿2021/06/04 08:26

Wordpressでカスタム投稿タイプを生成したのですが、記事の内容のループをsingle-(カスタム投稿タイプ名).phpに張り付けたのですが、内容が反映されません。
原因がわからず挫折しています。

functionPHP

1function cpt_register_works() { //add_actionの2つのパラメーターを定義 2 $labels = [ 3 "singular_name" => "topic", 4 "edit_item" => "topic", 5 ]; 6 $args = [ 7 "label" => "topic", //管理画面に出てくる名前 8 "labels" => $labels, 9 "description" => "", 10 "public" => true, 11 "show_in_rest" => true, 12 "rest_base" => "", 13 "rest_controller_class" => "WP_REST_Posts_Controller", 14 "has_archive" => true, 15 "delete_with_user" => false, 16 "exclude_from_search" => false, 17 "map_meta_cap" => true, 18 "hierarchical" => true, 19 "rewrite" => [ "slug" => "works", "with_front" => true ], //スラッグをworksに設定 20 "query_var" => true, 21 "menu_position" => 5, 22 "supports" => [ "title", "editor", "thumbnail" ], 23 ]; 24 register_post_type( "works", $args ); 25} 26add_action( 'init', 'cpt_register_works' ); 27 28 29 30function cpt_register_dep() { //add_actionの2つのパラメーターを定義 31 $labels = [ 32 "singular_name" => "dep", 33 ]; 34 $args = [ 35 "label" => "カテゴリー", 36 "labels" => $labels, 37 "publicly_queryable" => true, 38 "hierarchical" => true, 39 "show_in_menu" => true, 40 "query_var" => true, 41 "rewrite" => [ 'slug' => 'dep', 'with_front' => true, ], //カテゴリーのスラッグ 42 "show_admin_column" => false, 43 "show_in_rest" => true, 44 "rest_base" => "dep", 45 "rest_controller_class" => "WP_REST_Terms_Controller", 46 "show_in_quick_edit" => false, 47 ]; 48 register_taxonomy( "dep", [ "works" ], $args ); //「works」というカスタム投稿タイプにカテゴリーを追加 49} 50add_action( 'init', 'cpt_register_dep' ); 51?>

singletopicPHP

1 <? 2 /* 3 Template Name: topicレイアウト 4 */ 5 ?> 6 7<div id="single"> 8 9 10<?get_header();?> 11<div class="flex"> 12 13 14<div id="single_article"> 15 16<?php if(have_posts()): while(have_posts()):the_post(); ?> 17<a href="<?php the_permalink(); ?>"> 18<time datetime="<?php the_time('Y-m-d'); ?>"><?php the_time('Y.m.d'); ?></time> 19 <div id="single_title"><?php the_title(); ?></div> 20<img id="single_thumbnail" src="<?php echo get_the_post_thumbnail( $post_id, $size, $attr ); ?> 21</a> 22<p><?php the_content('Read more'); ?></p> 23 24<?php endwhile; endif; ?> 25 26 27 28</div> 29<?get_sidebar();?> 30</div> 31<?get_footer();?> 32 33 34</div>

CSS

1*{ 2 font-family: serif; 3 margin:0; 4} 5 6h1,h2,h3,h4,h5,h6{ 7 text-align:center; 8 9} 10 11img{ 12 width:100%; 13 height:auto; 14 object-fit:cover; 15} 16 17i{ 18 opacity: 0.5; 19} 20 21i:hover{ 22 opacity:1; 23 transition: all 1s; 24} 25 26a{ 27 color: black; 28 text-decoration: none; 29} 30 31iframe{ 32 width:100%; 33} 34 35.margin{ 36 margin:2.5%; 37 width:95%; 38} 39.blank{ 40margin-top:50px; 41} 42 43.img{ 44width:100px; 45} 46 47.center{ 48 width:100%; 49 text-align:center; 50} 51 52 53.plate{ 54border: 1px solid #eee; 55text-align:center; 56padding:10px 0; 57} 58 59.flex{ 60 display:flex; 61} 62 63.btn{ 64 width: 80%; 65 margin:0 10%; 66 text-align: center; 67 border:1px solid; 68 background-color: black; 69 color: white; 70 border-radius: 3px; 71 padding:5px 0; 72 opacity:0.5; 73 transition: all 1s; 74} 75 76.btn:hover{ 77 opacity:1; 78} 79 80.blank{ 81 margin-top:50px; 82} 83 84#all{ 85background-color:#eee; 86} 87 88 89#header_contents{ 90 margin:0 18%; 91 display: flex; 92 93} 94 95#header_contents_left{ 96 height:50px; 97 width: 50%; 98 text-align:left; 99 100} 101 102#header_contents_left ul{ 103 display:flex; 104 list-style: none; 105} 106 107#header_contents_left li{ 108 margin: 10px 5px; 109} 110 111 112#header_contents_right{ 113 height:50px; 114 line-height:50px; 115 width: 50%; 116  text-align: right; 117 display:flex; 118} 119 120#header_contents_right i{ 121font-size: 20px; 122margin:0 5px; 123} 124 125#header_title{ 126 border-top: 1px solid #eee; 127 border-bottom: 1px solid #eee; 128 text-align: center; 129 padding: 50px 0; 130 transition: all 1s; 131} 132 133#header_title h1{ 134 display: inline; 135} 136 137#body{ 138 display: flex; 139 margin:0 20%; 140} 141 142#top{ 143 width: 68%; 144 margin:0 1%; 145 146} 147#top img{ 148 width:100%; 149 margin:0%; 150 height:45%; 151 object-fit:cover; 152} 153 154#top_article{ 155background-color:whitesmoke; 156} 157 158#top_article h1,#top_topic h1{ 159text-align:center; 160font-size:15px; 161color:gray; 162} 163 164#top_article h2,#top_topic h2{ 165width:90%; 166margin:0 5%; 167text-align:; 168font-size:20px; 169} 170 171#top_article article{ 172 opacity:0.7; 173 transition:all 1s; 174} 175#top_article article:hover{ 176 opacity:1; 177} 178 179 180#sidebar{ 181 width: 24%; 182 margin: 0 15% 0 1%; 183 184} 185 186#sidebar_serch{ 187 width:100%; 188 text-align:center; 189} 190 191#sidebar_about img{ 192 width: 50%; 193 margin:0 25%; 194 border-radius:50%; 195} 196 197#sidebar_about p:nth-child(3){ 198width: 100%; 199text-align: center; 200} 201 202#sidebar_sns_contents{ 203 width: 60%; 204 margin:0 20%; 205 text-align: center; 206} 207 208#sidebar_sns_contents i{ 209 width:20%; 210} 211 212#sidebar_popular_thumbnail img{ 213 width:100%; 214 height:200px; 215} 216 217#footer{ 218 height:100px; 219 background-color: black; 220 display: flex; 221} 222 223#footer p{ 224 line-height:100px; 225 color:white; 226 width:28%; 227 margin:0 1% ; 228 text-align: right; 229 230} 231 232#footer a{ 233 line-height:100px; 234 color:white; 235 width:40%; 236 margin-left: 30%; 237 text-align:center; 238 239} 240 241#single{ 242 line-height:50px; 243} 244 245#single_title{ 246 font-size:28px; 247 font-weight:bold; 248 margin-bottom:10px; 249} 250 251#single_article{ 252 width:45%; 253 margin:0 0 0 15%; 254 255} 256 257#single_article img{ 258 width:100%; 259 height:auto; 260 object-fit: unset; 261 margin:0 %; 262} 263 264#single_article time{ 265 width:100%; 266 text-align:center; 267 display:block; 268} 269 270#single_article h1{ 271 width:100%; 272 font-size:25px; 273 background-color:#eee; 274 border-left:10px solid orange; 275} 276 277 278 279#single_article h2{ 280 281 282} 283 284#single_article h2:before{ 285 width:100%; 286 content:'✔'; 287 color:orange; 288 289} 290 291#single_article h3{ 292 width:100%; 293 294} 295 296#single_article ul{ 297background-color:#eee; 298 299} 300 301#single_mokuji { 302 background-color:whitesmoke; 303 width:; 304 padding:10px; 305} 306 307#single_mokuji strong:before { 308content:"・"; 309} 310 311#single_mokuji strong{ 312 width:40%; 313 margin:10px 30%; 314 display:block; 315 316} 317 318 319#single_thumbnail{ 320 width:100%; 321 height:45%; 322} 323 324#contact_form{ 325 margin:100px 0; 326} 327 328#about{ 329 margin:0 20%; 330} 331 332#about_face p{ 333 width:70%; 334 margin:auto; 335} 336 337#about_face img{ 338 width:20%; 339 margin:0 5%; 340} 341 342#about_service_content1, 343#about_service_content2, 344#about_service_content3 345{ 346width:31.3%; 347margin:0 1%; 348} 349 350 351#about_service_content1 i, 352#about_service_content2 i, 353#about_service_content3 i 354{ 355 font-size:80px; 356 margin:10px 0; 357} 358 359 360#about_work img{ 361 width:45%; 362 margin:2.5%; 363 object-fit:cover; 364} 365 366#search{ 367 margin:0 20%; 368 width:60%; 369} 370 371#search_article{ 372 width: 68%; 373 margin:0 1%; 374} 375 376#search_article img{ 377 width:100%; 378 margin:0%; 379 height:450px; 380 object-fit:cover; 381} 382 383#search_article h1,h2{ 384 width:100%; 385 text-align:center; 386} 387 388 389@media (max-width:1000px) { 390 391 iframe{ 392 width:100%; 393 height:200px; 394} 395.margin{ 396 margin:0 15%; 397 width:70%; 398} 399 400.flex{ 401 display:block; 402} 403 #header_contents{ 404 margin:0%; 405 display: flex; 406 407 } 408 409 #header_contents_left{ 410 height:50px; 411 width: 50%; 412 text-align:left; 413 } 414 #header_contents_right{ 415 height:50px; 416 line-height:50px; 417 width: 50%; 418 text-align: right; 419 } 420 421 #footer{ 422 height:100px; 423 background-color: black; 424 display: block; 425} 426#footer p{ 427display:none; 428 429} 430 431#footer a{ 432 line-height:100px; 433 color:white; 434 width:100%; 435 margin-left: 0%; 436 text-align:center; 437 438} 439 440 #body{ 441 display:block; 442 margin:0 2%; 443 } 444 445 #top{ 446 width: 100%; 447 margin: 17px 0%; 448 } 449 450 #top_article article{ 451 opacity:1; 452} 453 #sidebar{ 454 width: 100%; 455 margin: 0%; 456 } 457 458 #sidebar_about p:nth-child(3){ 459 width: 80%; 460 margin: 10%; 461 } 462 463#single_article{ 464 width:95%; 465 margin:0 2.5%; 466} 467 468#single_mokuji strong{ 469 background-color:#eee; 470 width:80%; 471 margin:10%; 472} 473 474#about{ 475 margin:0 5%; 476} 477 478#about_face p{ 479 width:50%; 480 margin:0 25%; 481} 482 483#about_face img{ 484 width:50%; 485 margin:0 25%; 486} 487 488#about_service_content1, 489#about_service_content2, 490#about_service_content3 491{ 492width:70%; 493margin:0 15%; 494} 495 496 497#about_service_content1 i, 498#about_service_content2 i, 499#about_service_content3 i 500{ 501 font-size:80px; 502 margin:10px 0; 503} 504 505 506#about_work img{ 507 width:70%; 508 margin:20px 15%; 509 object-fit:cover; 510} 511 512#search{ 513 margin:0 0%; 514 width:100%; 515} 516 517#search_article{ 518 width: 100%; 519 margin:0%; 520} 521 522#search_article img{ 523 width:100%; 524 margin:0%; 525 height:45%; 526 object-fit:cover; 527} 528 529#search_article h1,h2{ 530 width:100%; 531 text-align:center; 532} 533 534 535} 536 537 538

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

CHERRY

2021/06/04 23:52

> 内容が反映されません。 とは、どのような状況でしょうか? 具体的に起きている状況を記載していただけないでしょうか?
Nemuu

2021/06/05 15:28 編集

情報不足で大変失礼しました。 front-page.phpで出力されてるカスタム投稿タイプの記事をクリックしても、 single.phpに入力されている、header,footer,sidebar情報は出力されているのですが、記事内容や日付が出力されません。
guest

回答1

0

singletopicPHPって書いてあるが、もしsingle-topic.phpにしてるなら大間違いだろ。
register_post_type( "works", $args );だからpost_typeはworksだろ。

投稿2021/06/06 11:34

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問