我在页面上有一个链接列表,每个链接都链接到页面上一个 div 的 id。这个想法是在点击时,一个带有内联内容的模式启动。
HTML如下:
<a href="#cardiacModal">Cardiac Care</a>
<a href="#emergencyModal">Emergency</a>
.... and many more
和模态:
<div style="display:none">
<div id="cardiacModal">
<?php query_posts( array('p' => 57, 'post_type' => 'directions') );
if (have_posts()) : while (have_posts()) : the_post(); ?>
<p><?php the_title(); ?></p>
<?php endwhile; endif; ?>
</div>
<div id="emergencyModal">
<?php query_posts( array('p' => 54, 'post_type' => 'directions') );
if (have_posts()) : while (have_posts()) : the_post(); ?>
<p><?php the_title(); ?></p>
<?php endwhile; endif; ?>
</div>
... and many more
</div>
总共有大约 50 个不同的链接触发 50 个单独的模态。在每个模式中,我使用 php 从特定的 Wordpress 页面中提取内容。现在,这个页面开始变得有点重,有超过 800 行代码!
我正在寻找一种不同的方法 - 有一个带有条件语句的单一模式,如果用户点击链接x,那么我们想在 wordpress中查询页面 id x 。
我真的不确定解决此问题的最佳方法,或者是否可能。我基本上是在寻找一种替代解决方案来避免使用 50 个模式 - 我宁愿拥有一个具有控制从哪个 wordpress 页面内容中提取的逻辑的模式。
目前,我认为最好的解决方案是将每个模式放在一个单独的 php 文件中并使用 jquery 加载该 ajax ......但我更喜欢替代解决方案。想法?