自定义字段未显示在自定义 post 类型中
Custom fields not showing in custom post type
我正在整理一个基本的登录页面 http://shurity.com/,在尝试清理我的代码时,我想为用户用动态内容替换一些静态内容。
有问题的元素是单击订阅时弹出的模式...当我尝试将其包含在循环中时,我的文本没有显示。下面的代码是一个模板文件,匹配我为模式创建的自定义 post 类型,post 类型有 3 个自定义字段,用于标题、body 和模式的页脚文本。 the_content() 正在拉动实际形式。
<?php
$modal_header = get_field('modal_header');
$modal_body = get_field('modal_body');
$modal_footer = get_field('modal_footer');
?>
<!-- MODAL
================================================== -->
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<?php
$args = array(
'post_type' => 'modal',
'posts_per_page' => 1
);
$loop = new WP_Query($args); ?>
<?php
if ( $loop -> have_posts() ) :
/* Start the Loop */
while ( $loop -> have_posts() ) : $loop -> the_post();
/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
//get_template_part( 'template-parts/content', get_post_format() );
?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel"><i class="fa fa-envelope"></i> <?php echo $modal_header; ?></h4>
</div><!-- modal-header -->
<div class="modal-body">
<p><?php echo $modal_body; ?></p>
<?php the_content(); ?>
</div><!-- modal-body -->
<hr>
<p><small><?php echo $modal_footer; ?></small></p>
<?php endwhile;
else :
get_template_part( 'template-parts/content', 'none' );
endif; ?>
<?php wp_reset_postdata(); ?>
</div><!-- modal-content -->
</div><!-- modal-dialog -->
</div><!-- modal -->
我在 footer.php 中调用此模板部分。我是 Wordpress 的新手,所以如果错误很明显,请原谅。基本上表格出现了,但我的三个自定义字段没有出现。这是现在的样子..
您正在尝试获取实际 WP_Query 之前的字段。
将此代码放入循环中:
while ( $loop -> have_posts() ) : $loop -> the_post();
$modal_header = get_field('modal_header');
$modal_body = get_field('modal_body');
$modal_footer = get_field('modal_footer');
....
我正在整理一个基本的登录页面 http://shurity.com/,在尝试清理我的代码时,我想为用户用动态内容替换一些静态内容。
有问题的元素是单击订阅时弹出的模式...当我尝试将其包含在循环中时,我的文本没有显示。下面的代码是一个模板文件,匹配我为模式创建的自定义 post 类型,post 类型有 3 个自定义字段,用于标题、body 和模式的页脚文本。 the_content() 正在拉动实际形式。
<?php
$modal_header = get_field('modal_header');
$modal_body = get_field('modal_body');
$modal_footer = get_field('modal_footer');
?>
<!-- MODAL
================================================== -->
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<?php
$args = array(
'post_type' => 'modal',
'posts_per_page' => 1
);
$loop = new WP_Query($args); ?>
<?php
if ( $loop -> have_posts() ) :
/* Start the Loop */
while ( $loop -> have_posts() ) : $loop -> the_post();
/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
//get_template_part( 'template-parts/content', get_post_format() );
?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel"><i class="fa fa-envelope"></i> <?php echo $modal_header; ?></h4>
</div><!-- modal-header -->
<div class="modal-body">
<p><?php echo $modal_body; ?></p>
<?php the_content(); ?>
</div><!-- modal-body -->
<hr>
<p><small><?php echo $modal_footer; ?></small></p>
<?php endwhile;
else :
get_template_part( 'template-parts/content', 'none' );
endif; ?>
<?php wp_reset_postdata(); ?>
</div><!-- modal-content -->
</div><!-- modal-dialog -->
</div><!-- modal -->
我在 footer.php 中调用此模板部分。我是 Wordpress 的新手,所以如果错误很明显,请原谅。基本上表格出现了,但我的三个自定义字段没有出现。这是现在的样子..
您正在尝试获取实际 WP_Query 之前的字段。
将此代码放入循环中:
while ( $loop -> have_posts() ) : $loop -> the_post();
$modal_header = get_field('modal_header');
$modal_body = get_field('modal_body');
$modal_footer = get_field('modal_footer');
....