0

我在页面上有一个链接列表,每个链接都链接到页面上一个 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 ......但我更喜欢替代解决方案。想法?

4

2 回答 2

0

您可以在同一页面中接收所有内容,例如“ http://domain.com/clinic?c=cardiacModal ”,因此,在您的页面中放置如下 switch 语句:

<?php
switch($_GET['c']){
   case 'cardiacModal' : $p = 57; break;
   case 'emergencyModal' : $p = 54; break;
   "..."
   default;
}
if(!empty($_GET['c']): ?>
 <div id="cardiacModal">
  <?php query_posts( array('p' => $p, 'post_type' => 'directions') );
    if (have_posts()) : 
        while (have_posts()) : the_post(); ?>
          the_title();
        <?php endwhile; 
    endif; ?>
  </div>
<?php endif; ?>
于 2013-05-03T16:25:06.640 回答
0

我将为模态框内容页面创建一个超级准系统页面模板(基本上只是内容的容器,所需的最低限度的 css),然后将其作为 iframe 或使用 AJAX 导入模态框。

于 2013-05-03T17:35:35.610 回答