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

質問編集履歴

1

コードを掲載しました。

2020/04/27 05:35

投稿

HD-evo87
HD-evo87

スコア7

title CHANGED
File without changes
body CHANGED
@@ -3,8 +3,95 @@
3
3
 
4
4
  カスタムフィールドの管理にはACF(Advanced Custom Fields)とCPT UI(Custom Post Type UI)の2つのプラグインを使用しており、アーカイブページはテーマディレクトリ内のルートにある「index.php」を「archive-{post-type}.php」にリネームしただけで表示することができました。
5
5
 
6
- しかし同様にindex.phpを「single-{post-type}.php」にリネームし、いくつかカスタムフィールド表示用のコードを書いてみたところ、投稿ページには何も表示されませんでした。
6
+ しかし同様にindex.phpを「single-{post-type}.php」にリネームし、以下のようにカスタムフィールド表示用のコードを記載したところ、投稿ページには何も表示されませんでした。
7
+ (「追記箇所」から「追記箇所ここまで」が自分で記載したコードです)
7
8
 
9
+ ```PHP
10
+ <?php
11
+ /**
12
+ * The main template file. Includes the loop.
13
+ *
14
+ *
15
+ * @package Customizr
16
+ * @since Customizr 1.0
17
+ */
18
+ if ( apply_filters( 'czr_ms', false ) ) {
19
+ do_action( 'czr_ms_tmpl' );
20
+ return;
21
+ }
22
+ ?>
23
+ <?php do_action( '__before_main_wrapper' ); ##hook of the header with get_header ?>
24
+ <div id="main-wrapper" class="<?php echo implode(' ', apply_filters( 'tc_main_wrapper_classes' , array('container') ) ) ?>">
25
+
26
+ <?php do_action( '__before_main_container' ); ##hook of the featured page (priority 10) and breadcrumb (priority 20)...and whatever you need! ?>
27
+
28
+ <div class="container" role="main">
29
+ <div class="<?php echo implode(' ', apply_filters( 'tc_column_content_wrapper_classes' , array('row' ,'column-content-wrapper') ) ) ?>">
30
+
31
+ <?php do_action( '__before_article_container'); ##hook of left sidebar?>
32
+
33
+ <div id="content" class="<?php echo implode(' ', apply_filters( 'tc_article_container_class' , array( CZR_utils::czr_fn_get_layout( czr_fn_get_id() , 'class' ) , 'article-container' ) ) ) ?>">
34
+
35
+ <?php do_action ('__before_loop');##hooks the heading of the list of post : archive, search... ?>
36
+
37
+ <?php if ( czr_fn__f('__is_no_results') || is_404() ) : ##no search results or 404 cases ?>
38
+
39
+ <article <?php czr_fn__f('__article_selectors') ?>>
40
+ <?php do_action( '__loop' ); ?>
41
+ </article>
42
+
43
+ <?php endif; ?>
44
+
45
+ <?php if ( have_posts() && ! is_404() ) : ?>
46
+ <?php while ( have_posts() ) : ##all other cases for single and lists: post, custom post type, page, archives, search, 404 ?>
47
+ <?php the_post(); ?>
48
+
49
+ <?php do_action ('__before_article') ?>
50
+ <article <?php czr_fn__f('__article_selectors') ?>>
51
+ <?php do_action( '__loop' ); ?>
52
+ </article>
53
+ <!--追記箇所-->
54
+ <div class="example">
55
+ <?php
56
+ $image = get_field('c_mainimage');
57
+ $size = 'medium'; // (thumbnail, medium, large, full or custom size)
58
+ if( $image ) {
59
+ echo wp_get_attachment_image( $image, $size );
60
+ }
61
+ ?>
62
+ </div>
63
+ <dl>
64
+ <dt>アルバム名</dt><dd><?php the_field('example-album'); ?></dd>
65
+ <dt>アーティスト名</dt><dd><?php the_field('example-artist'); ?></dd>
66
+ <dt>レビュー</dt><dd><?php echo nl2br(get_post_meta($post->ID, 'example-review', true)); ?></dd>
67
+ </dl>
68
+ <!--追記箇所ここまで-->
69
+
70
+ <?php do_action ('__after_article') ?>
71
+
72
+ <?php endwhile; ?>
73
+
74
+ <?php endif; ##end if have posts ?>
75
+
76
+ <?php do_action ('__after_loop');##hook of the comments and the posts navigation with priorities 10 and 20 ?>
77
+
78
+ <?php // <hr> introduced in july 2019 to fix https://github.com/presscustomizr/customizr/issues/1767 ?>
79
+ <hr class="featurette-divider tc-mobile-separator">
80
+ </div><!--.article-container -->
81
+
82
+ <?php do_action( '__after_article_container'); ##hook of right sidebar ?>
83
+
84
+ </div><!--.row -->
85
+ </div><!-- .container role: main -->
86
+
87
+ <?php do_action( '__after_main_container' ); ?>
88
+
89
+ </div><!-- //#main-wrapper -->
90
+
91
+ <?php do_action( '__after_main_wrapper' );##hook of the footer with get_footer ?>
92
+
93
+ ```
94
+
8
95
  どうやら「single-{post-type}.php」の中でtemplate>parts>content>singular>post_content.phpを呼び出しているようだということまではわかったのですが、知識がなくここからどうしていいか全くわからず途方に暮れています。
9
96
 
10
97
  どのphpファイルのどこにカスタムフィールド用のコード(<?php the_field('example'); ?>など)を書けばよいかなど