3

我的 wordpress 网站上有一些类别页面和单个页面,带有自定义查询。在主页上工作的分页基于在同一页面上加载帖子的脚本。

问题是分页仅适用于单页和类别,<?php previous_posts_link('&laquo; Previous') ?> 该脚本不适用于单页和类别。

这是代码:

<div class="main_container">
<div id="load_posts_container">
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
   $args=array(
      'post_type'=>'post',
      'cat' => '-28' . $category_ID,
      'posts_per_page' => 8,
      'paged'=>$paged
   );
   $temp = $wp_query;
   $wp_query= null;
   $wp_query = new WP_Query($args);

   if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();   ?>
<!--ARTICLES MARKUP HERE-->
<?php   endwhile; endif; 
   ?>
<!--//load_posts_container-->
<
<div class="load_more_cont">
   <p>Altri eventi <br/>
      <span class="load_more_text"><?php next_posts_link('<img src="' . get_bloginfo('stylesheet_directory') . '/images/load-more-image.png" alt="Altri Eventi a Roma"/>', $wp_query->max_num_pages) ?></span>
   </p>
</div>
<!--//load_more_cont-->
<?php $wp_query = null;
   $wp_query = $temp;
   wp_reset_query(); ?>
<script type="text/javascript">
   // Ajax-fetching "Load more posts"
   $('.load_more_cont a').live('click', function(e) {
    e.preventDefault();
    //$(this).addClass('loading').text('Loading...');
           //$('.load_more_text a').html('Loading...');
    $.ajax({
        type: "GET",
        url: $(this).attr('href') + '#main_container',
        dataType: "html",
        success: function(out) {
            result = $(out).find('#load_posts_container .home_post_box');
            nextlink = $(out).find('.load_more_cont a').attr('href');
                           //alert(nextlink);
            //$('#boxes').append(result).masonry('appended', result);
                       $('#load_posts_container').append(result);
            //$('.fetch a').removeClass('loading').text('Load more posts');
                           //$('.load_more_text a').html('Load More');


            if (nextlink != undefined) {
                $('.load_more_cont a').attr('href', nextlink);
            } else {
                $('.load_more_cont').remove();
                                   $('#load_posts_container').append('<div class="clear"></div>');
                                 //  $('.load_more_cont').css('visibilty','hidden');
            }

                       if (nextlink != undefined) {
                           $.get(nextlink, function(data) {
                             //alert(nextlink);
                             if($(data + ":contains('home_post_box')") != '') {
                               //alert('not found');
                                 //                      $('.load_more_cont').remove();
                                                       $('#load_posts_container').append('<div class="clear"></div>');        
                             }
                           });                        
                       }

        }
    });
   });
</script>

任何想法?谢谢

4

1 回答 1

0

如果 WordPress 没有为这些页面解析分页查询变量(我尚未验证),您可能想跳过get_query_var('paged'),并使用简单的旧方式$_GET['paged']

于 2014-01-17T00:54:17.823 回答