jQuery(document).ready(function($) {
$('a.ttLinks').click(function() {
var url= $(this).attr("href");
$("#inCenter>[id^=featuredv]").load(url);
return false;
});
});
我试着制作一个脚本,它在点击时加载链接的内容而不是重新加载页面。我不确定为什么,但看起来当点击一个链接时,它会将我目前正在使用的实际页面加载到我的featuredv div中,而不仅仅是帖子的内容。我认为当一个固定链接被点击时,它会将该链接加载到index.php中,然后将该页面返回给我。如何在单击链接时将帖子内容加载到div中?
<div id="ttContent">
<?php
query_posts('meta_key=featuredt&posts_per_page=5');
if (have_posts()) : while (have_posts()) : the_post();
?>
<div id="featuredt-<?php echo $wp_query->current_post;?>">
<a class="ttLinks" rel="<?php the_permalink(); ?>" href="<?php echo the_permalink();?>">
<?php echo get_post_meta($post->ID, 'featuredt', TRUE);?></a></div>
<?php endwhile;
endif;
?>
</div>
上面的代码是我使用生成我的链接,我本来用的href但阅读另一篇文章,Load Wordpress post content into DIV using AJAX后,我想,也许我应该尝试使用rel标签,而不是PHP,有WASN”因为任何方式的网址是相同的,但我累了,尽我所能地尝试。
<div id="inCenter">
<?php
query_posts('meta_key=featuredt&posts_per_page=1');
if (have_posts()) : while (have_posts()) : the_post();?>
<div id="featuredv-<?php echo $wp_query->current_post;?>">
<?php echo $post->post_content;?></div>
<?php endwhile;
endif;
?>
</div>
而这段代码是什么生成的内容,我想要替换时点击链接。 什么萤火虫似乎显示的是,第一次点击一个链接,它会发送一个GET请求永久链接在它显示的页面,第二次点击任何链接时,它会发送4个GET请求永久链接,下一次12等等。我没有使用wordpress作为博客,我没有地方加载帖子,所以也许这些帖子是使用index.php默认加载的,当GET请求被创建时?再次感谢您的帮助。
你可以发布你的HTML吗?你发布的JavaScript显然是不好的。你能修好它吗? – mrtsherman
你将需要做更多的工作来获得帮助,使用萤火虫 - 看看会发生什么回来(也许有重定向) –
我做了一些额外的工作,让我知道如果我需要提供任何信息,感谢您采取该回应我的时候了。 – redappleorigin