【发布时间】:2016-12-28 17:21:44
【问题描述】:
我没有找到解决此类错误的任何方法。我在我的 wordpress 网站上添加了一个分页。一切正常。但是当我点击 2,3,4...等页面时它不会改变它的类.current 这就是为什么它没有得到.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 类。谁能告诉我问题出在哪里?
提前致谢。如果您需要更多代码,请告诉我。
【问题讨论】:
-
你能告诉我们分页码吗?
-
@ChoncholMahmud : 你添加类的 JS 代码在哪里?
-
你能在这里阅读答案吗 - wordpress.stackexchange.com/questions/126080/…
-
@YoYo 我认为
.current是wordpress 类。我没有为这个类添加任何js。 -
可以粘贴2、3、4等的onclick函数吗?
标签: php css wordpress pagination