在第二页滑块上没有显示分页

时间:2016-03-21 11:00:46

标签: wordpress pagination

我创建了一个短代码,用于使用带分页的自定义帖子类型获取帖子,并且它工作正常但是当我使用分页滑块去第二页时没有显示。这是我使用的代码:

 <?php  function artistCategoryFunction($args){
                        global $wpdb;
                        global $posts;
                        $term = get_term($args['categoryid'],'artists_category');
                        $name = $term->slug;
                        $catId = explode(',',$args['categoryid']);
                        $perPage = $args['post_per_page'];
                        $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
                        $posts_array = new WP_Query(
                       $data =  array(
                            'posts_per_page' => $perPage,
                            'post_type' => 'artists',
                            'paged' => $paged,
                            'tax_query' => array(
                                array(
                                    'taxonomy' => 'artists_category',
                                    'field' => 'term_id',
                                    'terms' => $catId,
                                    'operator'=> 'IN'

                                )
                            )
                        )
                    );
                        //echo '<pre>';print_r($posts_array->posts);
                        $grid = '<div class="category"><ul>';
                    if ( $posts_array->have_posts() ) : while ( $posts_array->have_posts() ) : $posts_array->the_post(); 
                                 $post_id = $values->ID;
                                 $title = get_the_title();
                                 $thisposts = get_post($post_id);
                                 $thisposts = $thisposts->post_name;
                                 $mobile_img = get_field('featured_mobile_image');
                                 $content = get_field('description_(short)');
                                 $feature_img = wp_get_attachment_url( get_post_thumbnail_id());
                                    if($mobile_img == '')
                                    {
                                    $mobile_img = $feature_img;
                                    }
                                    else{
                                     $mobile_img; 
                                    }
                    $grid .= '<li><div class="cate-box">
                                    <div class="cate-pic"><a href="/artists/'.$name.'/'.$thisposts.'"><img src="'.$mobile_img.'" alt=" "></a></div>
                                    <div class="cate-ctn">
                                    <h4>'.$title.'</h4><p>'.$content.
                                    '</p><span class="read-box"><a href="/artists/'.$name.'/'.$thisposts.'" class="read">read more</a></span>
                                        </div></div></li>';
                                    endwhile;endif;wp_reset_query();
                                    $total_pages = $posts_array->max_num_pages;
                                    if ($total_pages > 1){
                                    $current_page = max(1, get_query_var('paged'));
                      $grid .= '<div class="page_nav">';
                      $grid .= paginate_links(array(
                          'base' => get_pagenum_link(1) . '%_%',
                          'format' => 'page/%#%',
                          'current' => $current_page,
                          'total' => $total_pages,
                          'prev_text' => 'Prev',
                          'next_text' => 'Next'
                        ));
                      $grid .= '</div>';
                    }
                                    $grid .= '</ul></div>';
                                    return $grid; 
                    }
                    add_shortcode('artistGrid','artistCategoryFunction');?>

1 个答案:

答案 0 :(得分:0)

我的一个网站中有一个类似的问题,在我的情况下,problam位于$paged变量中,并且更准确地说就是它的值。

您可以尝试使用此代码,它适用于我:

$paged = get_query_var( 'paged' ) ?: ( get_query_var( 'page' ) ?: 1 );