[英]Querying Different Wordpress pages depending on href value of clicked link
I have a list of links on a page, each linking to an id of a div on the page. 我在页面上有一个链接列表,每个链接都链接到页面上的div的ID。 The idea is that on click, a modal launches with the inline content.
这个想法是,单击后,将启动带有内联内容的模式。
The HTML is as follows: HTML如下:
<a href="#cardiacModal">Cardiac Care</a>
<a href="#emergencyModal">Emergency</a>
.... and many more
and the modals: 和模式:
<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>
In total, there are about 50 different links triggering 50 seperate modals. 总共大约有50个不同的链接触发50个单独的模态。 Within each modal I am using php to pull content from a specific Wordpress page.
在每个模式下,我都在使用php从特定的Wordpress页面提取内容。 Now, this page is starting to get a bit heavy weight with over 800 lines of code!
现在,此页面开始变得繁重,包含800余行代码!
I am looking for a different approach - to have one single modal with conditional statements saying, if the user clicked on link x , then we want to query page id x within wordpress. 我正在寻找一种不同的方法-使用一个带有条件语句的模态,如果用户单击链接x ,那么我们要在wordpress中查询页面ID x 。
Im really not sure the best way to go about this, or if it is even possible. 我真的不确定最好的方法,甚至可能。 I am basically looking for an alternate solution to avoid having 50 modals - I would rather have one modal with logic that controls which wordpress page content is being pulled from.
我基本上是在寻找一种避免使用50个模式的替代解决方案-我宁愿有一个带有控制从哪个wordpress页面内容中提取内容的逻辑的模式。
CURRENTLY, I think the best solution would be to place each modal in a separate php file and using jquery to load that ajax...but I would prefer an alternate solution. 目前,我认为最好的解决方案是将每个模式放在单独的php文件中,并使用jquery加载该ajax ...,但我更喜欢替代解决方案。 Thoughts?
有什么想法吗?
You can receive everything in the same page, like " http://domain.com/clinic?c=cardiacModal " so, in your page you put a switch statement like: 您可以在同一页面上收到所有内容,例如“ http://domain.com/clinic?c=cardiacModal ”,因此,在页面中您可以输入以下切换语句:
<?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传递到模式框中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.