0

好的,我有一个 wordpress 自定义循环遍历 3 个博客并返回如下结果:

<?php
                 $posts_per_page = get_option('posts_per_page');
                 $searchfor = get_search_query(); // Get the search query for display in a headline
                 $query_string=esc_attr($query_string); // Escaping search queries to eliminate potential MySQL-injections
                 $blogs = get_blog_list( 0,'all' );
                 $notfound = true;
                 $current_blogid=get_current_blog_id();
                 $blogs_ordered = array($current_blogid);

        foreach ( $blogs as $blog ):
                if ($blog['blog_id']!=$blogs_ordered['0']){
                        $blogs_ordered[]=$blog['blog_id'];
                }
        endforeach;

        foreach ( $blogs_ordered as $blogid ):
                switch_to_blog($blogid);
               $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
                              $search = new WP_Query($query_string.'&posts_per_page=1&paged='.$paged);               

                  if ($search->found_posts>0) {
                         foreach ( $search->posts as $post ) {

                             POST CONTENT ECHOS HERE!!!

                                <?php
                                $post = $postx;
                                wp_reset_query();
                            }
                        }
                     wp_reset_query();

        endforeach;
           $page_links_total =  $search->max_num_pages; 
                if ($page_links_total>1) :


                ?>

        <div class="navigation">
            <div class="nav">
                        <?

    $search->query_vars['paged'] > 1 ? $current = $search->query_vars['paged'] : $current = 1;
    $pagination_args = array(
        'base' => @add_query_arg('paged','%#%'),
        'format' => '',
        'total' => $page_links_total,
        'current' => $current,
        'show_all' => false,
        'end_size' => 0,
        'mid_size' => 0,
    );
    if ( $wp_rewrite->using_permalinks() ) $pagination['base'] = user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'paged/%#%/', 'paged' );
    if ( !empty($wp_query->query_vars['s']) ) $pagination['add_args'] = array( 's' => get_query_var( 's' ) );  

    $prev = get_previous_posts_link('< FORRIGE');
    $next = get_next_posts_link('NESTE >');

$links = paginate_links($pagination_args);
    $links = "
            <div class='left'>
                $prev    
            </div>
            <div class='class'> 
                $next
            </div>
    ". $links;
    echo $links;
            ?>
            </div>
            </div>

        <div class="navigation">

            <div class="nav">
                <div class="left">
                        <a href="<?php echo get_site_url(1) . "/?s=" . get_search_query() . '&paged=' . ($current - 1); ?>">< FORRIGE</a>
                </div>
            <div class='center'>Side <?php echo "$current/$page_links_total"; ?></div> 
                <div class="right">
                        <a href="<?php echo get_bloginfo('home') . "/page/" . ($current + 1) . "/"; ?>">NESTE ></a>
                        <?php echo the_search_query(); ?>
                        <a href="<?php echo get_site_url(1) . "/?s=" . the_search_query() . '&paged=' . ($current + 1); ?>">NESTE ></a>
                </div>
            </div>
        </div>
        <?php
        endif; 
?>

我的问题是,每当我尝试使用分页链接时,它只会刷新同一页面。如果我改变这个:

 $search = new WP_Query($query_string.'&posts_per_page=1&paged='.$paged);

至 :

  $search = new WP_Query($query_string.'&posts_per_page=1&paged=10');   

它确实会跳转到正确的页面,并且下一个上一个链接只是拒绝工作,我尝试关闭永久链接我尝试了无数不同的东西(有些仍在代码中..)请帮助这让我墙!亲切的问候克里斯

4

1 回答 1

0

我必须编写一个自定义分页变量,如果需要,您可以在此处找到整个工作循环: https ://github.com/vimes1984/Wordpress_multisite_search

于 2013-11-20T00:20:46.067 回答