2013-07-14 90 views
0

这是我的选项卡菜单,在这里用户可以选择选项卡加载WordPress的帖子点击锚

<div id="slider-menu" class="row"> 
    <div class="span12"> 
     <ul class="nav nav-tabs" id="myTab"> 
      <li class="active"><a href="#home">Latest events</a><div class="triangle"></div></li> 
      <li><a href="#profile">Our champions</a></li> 
      <li><a href="#messages">We have puppies!</a></li> 
     </ul> 
    </div> 
</div> 

而且有我的标签,其中内容被加载时,页面加载

<div class="tab-content"> 
     <div class="tab-pane active" id="home"> 
      <img src="<?php bloginfo('template_url'); ?>/img/slider.png" /> 
      <div class="span12"> 
       <?php 
       query_posts('cat=7'); 
        if (have_posts()) : while (have_posts()) : the_post(); ?> 
        <h3><a href="<?php the_permalink() ?>" rel="bookmark" title=""><?php the_title(); ?></a></h3> 
        <?php the_content(); ?> 
        <?php endwhile; else: ?> 
        <p>Sorry, no posts matched your criteria.</p> 
        <?php endif; ?> 
      </div> 
     </div> 
     <div class="tab-pane" id="profile"> 
      <img src="<?php bloginfo('template_url'); ?>/img/slider.png" /> 
      <div class="span12"> 
       <?php 
       query_posts('cat=8'); 
        if (have_posts()) : while (have_posts()) : the_post(); ?> 
        <h3><a href="<?php the_permalink() ?>" rel="bookmark" title=""><?php the_title(); ?></a></h3> 
        <?php the_content(); ?> 
        <?php endwhile; else: ?> 
        <p>Sorry, no posts matched your criteria.</p> 
        <?php endif; ?> 
      </div> 
     </div> 
     <div class="tab-pane" id="messages"> 
      <img src="<?php bloginfo('template_url'); ?>/img/slider.png" /> 
      <div class="span12"> 
       <?php 
       query_posts('cat=9'); 
        if (have_posts()) : while (have_posts()) : the_post(); ?> 
        <h3><a href="<?php the_permalink() ?>" rel="bookmark" title=""><?php the_title(); ?></a></h3> 
        <?php the_content(); ?> 
        <?php endwhile; else: ?> 
        <p>Sorry, no posts matched your criteria.</p> 
        <?php endif; ?> 
      </div> 
     </div> 
    </div> 

当会有很多帖子,它会将页面加载太久,所以我的基本想法是在页面加载时将所有帖子加载到第一个标签,并在用户选择它时将帖子加载到另一个标签。

我很努力如何结合wp文章循环和ajax加载帖子时,用户点击特定标签。

非常感谢您的帮助。

+0

[如果这有帮助](http://stackoverflow.com/questions/16127557/loading-database-content-via-xmlhttprequest-in-wordpress/16128067#16128067)。 –

回答

0
$.ajaxSetup({cache:false}); 
$('#myTab li').click(function(){ 
    var cat_id = $(this).children().attr('rel'); 
    $.get('location.href' + cat_id, function(data) { 
    $('#' + cat_id).html(data); 
return false; 
}); 

所以我输出类别id锚定rel属性,然后我添加点击事件处理程序,其中我调用.get函数。毕竟,我输出数据。