我没有找到解决此类错误的任何方法。我在wordpress网站上添加了分页功能,一切正常,但是当我单击2,3,4 ... etc页面时,它不会更改其类这就是为什么它没有获得.current类的CSS的原因。画廊的功能代码:function jellythemes_gallery($atts, $content=null) { extract( shortcode_atts( array( 'limit' => -1 ), $atts ) ); global $post; $back=$post; echo '<div id="portfolio"> <div class="section portfoliocontent"> <section id="i-portfolio" class="clear">'; // set up or arguments for our custom query $paged = ( get_query_var('page') ) ? get_query_var('page') : 1; $query_args = array( 'post_type' => 'media', 'posts_per_page' => 12, 'paged' => $paged ); // create a new instance of WP_Query $the_query = new WP_Query( $query_args ); if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); $image = get_post_meta( $post->ID, '_jellythemes_media_photo', true ); $video = get_post_meta( $post->ID, '_jellythemes_media_video', true ); $img = wp_get_attachment_image_src($image, 'media_thumb'); echo '<div class="ch-grid element"> <img class="ch-item" src="' . $img[0] .'" alt="' . get_the_title() . '" />'; if (empty($video)) { echo '<a class="fancybox img-lightbox" rel="" href="' . $img[0] .'">'; } else { echo '<a class="fancybox-media" rel="" href="' . $video.'">'; } echo '<div> <span class="p-category ' . (empty($video) ? 'photo' : 'video') . '"></span> </div> </a> </div>'; endwhile; $post=$back; //restore post object $return .= '</section> </div> </div>'; echo "<div class='pagination_center'>"; if ($the_query->max_num_pages > 1) { $current_page = max(1, get_query_var('paged')); echo paginate_links(array( 'base' => get_pagenum_link(1) . '%_%', 'format' => '/page/%#%', 'current' => $current_page, 'total' => $the_query->max_num_pages, 'show_all' => true, 'prev_text' => __('« PREV'), 'next_text' => __('NEXT »'), 'prev_next' => false, )); } else{ echo '<article> <h1>Sorry...</h1> <p>';echo 'Sorry, no posts matched your criteria.'; echo'</p> </article>'; } endif; echo "</div>"; return $return;}add_shortcode( 'jellythemes_gallery', 'jellythemes_gallery' );CSS:.pagination_center .current{border: 1px solid #c3121c; padding: 0px 5px; color: black; font-weight: bold; background: #c3121c;}在这里我添加了一个带检查元素的image。它是第2页,但是第1页的.current类,有人可以告诉我问题出在哪里吗?在此先感谢您。如果您需要任何其他代码,请告诉我。 (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 我也遇到了同样的问题,并修复了调试我的分页代码的问题。这是在静态首页中进行分页的解决方案。更换$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;与if ( get_query_var( 'paged' ) ) { $paged = get_query_var( 'paged' );} elseif ( get_query_var( 'page' ) ) { $paged = get_query_var( 'page' );}else { $paged = 1;}在您的WP_Query循环中。那你需要更换'current' => $current_page,与'current' => max( 1, $paged ),在您的paginate_links数组中。就我而言,它就像一种魅力。您也应该尝试一下。我相信它会100%工作。 (adsbygoogle = window.adsbygoogle || []).push({}); 09-25 20:06