Php 根据点击链接的href值查询不同的Wordpress页面
我在一个页面上有一个链接列表,每个链接都指向页面上一个div的id。其思想是,单击时,会启动一个带有内联内容的模式 HTML格式如下:Php 根据点击链接的href值查询不同的Wordpress页面,php,wordpress,dynamic,modal-dialog,Php,Wordpress,Dynamic,Modal Dialog,我在一个页面上有一个链接列表,每个链接都指向页面上一个div的id。其思想是,单击时,会启动一个带有内联内容的模式 HTML格式如下: <a href="#cardiacModal">Cardiac Care</a> <a href="#emergencyModal">Emergency</a> .... and many more .... 还有更多 情态动词: <div style="display:none"> &l
<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…但我更喜欢另一种解决方案。想法?您可以在同一页中接收所有内容,如“”,因此,在您的页中放置一个切换语句,如:
<?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; ?>
我会为模式框内容页面创建一个超级精简的页面模板(基本上只是内容的容器,最简单的css需要),然后将其作为iframe或AJAX导入模式中。是的,这正是我所希望的。让我来测试一下,很快就会回来。但是,为什么不使用WP‘页面’?您可以使用永久链接“%category%/%postname%”,并使用页面模板执行此操作。。。并在循环中列出所有页面链接以构建菜单。