<div class="col-lg-4 col-md-4 col-sm-6 exhibitors-child">
<div class="exhibitors-border">
<?php the_post_thumbnail(); ?>
<div class="find">
<a href="" data-toggle="modal" data-target="#exhibitors-child"><small>FIND OUT MORE</small></a>
</div>
</div>
</div>
<?php endwhile; endif; wp_reset_query(); ?>
<!-- Modal -->
<div class="modal fade" id="exhibitors-child" tabindex="-1" role="dialog" aria-labelledby="exhibitors-childLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<?php the_post_thumbnail(); ?>
<h2><?php echo get_field(\'name\') ;?></h2>
<p><?php echo get_field(\'exhibitors_single_description\') ;?></p>
</div>
</div>
</div>
</div>
我想在bootstrap modal中动态加载POST
2 个回复
SO网友:Liam Stewart
确保使用正确的模板。
如果您使用的是单一帖子类型模板,则可以在modal中使用。
<?php the_content(); ?>
在此处了解有关帖子类型模板的更多信息:https://codex.wordpress.org/Post_Type_TemplatesSO网友:grzybowski1911
这是否在单页模板、存档页模板、单帖子模板上?与主查询相关的代码应该在哪里?在没有背景的情况下,很难提供建议或解决方案。
如果您试图在页面模板上创建一个节,以便除了页面内容之外还可以拉入您的帖子,这将要求您进行二次查询以拉入这些帖子。
如果我所描述的是您想要做的,请看这里:https://developer.wordpress.org/reference/classes/wp_query/
基本上,您可以在主查询(即页面内容的来源)之外进行新的查询。下面是一个简单的示例。有许多其他参数可用于优化查询。
$newArgs = array(
\'post_type\' => \'post\',
);
$query = new WP_Query( $newArgs );
然后运行第二个循环并将模式代码放在其中,看起来您也在使用ACF,这应该很好。下面是一个基本示例:if ( $newArgs->have_posts() ) {
while ( $newArgs->have_posts() ) {
$newArgs->the_post();
//
// Modal code here
//
} // end while
} // end if
有关循环的更多信息,请点击此处:https://codex.wordpress.org/The_Loop结束