在一个页面上,我有这个代码,它获取每个链接中的文本并提醒我文本内部的内容。所以我知道变量工作正常:
<ul class="subpages-menu">
<li ><a class="clienttext" href="<?php bloginfo( 'template_url' ); ?>/incs/clients.php">All</a></li>
<li ><a class="clienttext" href="<?php bloginfo( 'template_url' ); ?>/incs/clients.php">Accountancy</a></li>
<li ><a class="clienttext" href="<?php bloginfo( 'template_url' ); ?>/incs/clients.php">Education</a></li>
<li ><a class="clienttext" href="<?php bloginfo( 'template_url' ); ?>/incs/clients.php">Financial</a></li>
<li ><a class="clienttext" href="<?php bloginfo( 'template_url' ); ?>/incs/clients.php">Hospitality</a></li>
<li ><a class="clienttext" href="<?php bloginfo( 'template_url' ); ?>/incs/clients.php">Insurance</a></li>
<li ><a class="clienttext" href="<?php bloginfo( 'template_url' ); ?>/incs/clients.php">Marketing / PR / Branding</a></li>
<li ><a class="clienttext" href="<?php bloginfo( 'template_url' ); ?>/incs/clients.php">Other</a></li>
<li ><a class="clienttext" href="<?php bloginfo( 'template_url' ); ?>/incs/clients.php">Recruitment</a></li>
<script type="text/javascript">jQuery(document).ready(function() {
jQuery('#clients-placeholder').html('<img class="preloader" src="<?php bloginfo( 'template_url' ); ?>/images/ajax-loader.gif" alt="Loading" title="Loading" />');
jQuery('#clients-placeholder').load('/all-clients .boxes-pages');
jQuery('.clienttext').click(function(e) {
var clientText = jQuery(e.target).text();
var url = jQuery(this).attr('href');
alert (clientText);
jQuery.post('<?php bloginfo( 'template_url' ); ?>/incs/clients.php', {clientText: clientText});
jQuery('#clients-placeholder').html('<img class="preloader" src="<?php bloginfo( 'template_url' ); ?>/images/ajax-loader.gif" alt="Loading" title="Loading" />');
jQuery('#clients-placeholder').load(url);
e.preventDefault();
return false;
});
});
</script>
在另一页client.php我有以下内容:
<ul class="boxes-pages">
<?php
$whichCat = $_post['clientText'];
// The Query
$the_query = new WP_Query( array('post_type' => 'ourclients', 'clientcategory' => $whichCat));
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
$content = get_the_content();
$content = strip_tags($content); ?>
<li>
<div class="box">
<a href="<?php the_permalink(); ?>">
<?php
if ( has_post_thumbnail() )
the_post_thumbnail( 'client-logos' );
else
echo '<img src="default-image.png" alt="Example Image" title="Example" />';
?>
</a>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<p><?php $options = get_option( 'thetech_text' ); echo $options; ?></p>
<div class="tabs-readmore">
<a href="/the-cloud/the-technology/">Read More</a>
<img class="readmore-bt" src="<?php bloginfo( 'template_url' ); ?>/images/readmore-bt.png" alt="Read More" title="Read More" />
</div><!-- end hero-readmore-->
</div><!-- end box -->
</li>
<?php endwhile;
// Reset Post Data
wp_reset_postdata();
?>
</ul>
当我点击链接时,会重新加载我想要的div但似乎不会发送变量clientText。我得到它已设置的警报,但似乎没有将它传递给clients.php
非常感谢任何帮助。
由于
答案 0 :(得分:0)
让我们重做帖子和加载函数,我甚至认为你不需要使用加载函数。
jQuery.post('<?php bloginfo( 'template_url' ); ?>/incs/clients.php', {clientText: clientText}, function(data){
//function(data) gets the data you want to return from the page.
jQuery('#clients-placeholder').html('<img class="preloader" src="<?php bloginfo( 'template_url' ); ?>/images/ajax-loader.gif" alt="Loading" title="Loading" />');
//maybe you want a setTimeout() here so your Loading image sticks around for awhile.
$('#clients-placeholder').html(data);
});