doulu8847 2013-11-14 20:30
浏览 89
已采纳

多站点wordpress搜索循环和分页?

OK I have a wordpress custom loop looping across 3 blogs and returning the results like so:

<?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; 
?>

My problem arrises that whenever i try and use the pagination links it just refreshes the same page. if i change this:

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

to :

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

it does jump to the right page and the next prev links just refuse to work, i've tried turning off permalinks I've tried a myraid of different things (some still in the code..) Please help this is driving me up the wall! Kind regards Chris

  • 写回答

1条回答 默认 最新

  • dousi2013 2013-11-20 00:20
    关注

    I had to write a custm paged variable you can find the whole working loop here if it's needed: https://github.com/vimes1984/Wordpress_multisite_search

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用