2016-08-22 59 views
0

我沒有找到任何方法來解決這種類型的錯誤。我在我的wordpress網站上添加了分頁。所有的東西都可以。但是當我點擊2 ,3,4 ...等頁面不改變其類.current這就是爲什麼它沒有得到.current類的CSS。對於畫廊。當前類沒有改變,當我點擊WordPress站點中的分頁

功能代碼:

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與檢查element.It是第2頁,但是,頁面1.可.current類有人告訴我問題在哪裏?

在此先感謝。如果您需要進一步的任何代碼,請讓我知道。

+0

你能告訴我們分頁代碼plz –

+0

@ChoncholMahmud:你在哪裏添加類的JS代碼? –

+0

你可以在這裏閱讀答案 - http://wordpress.stackexchange.com/questions/126080/changing-pagination-list-class –

回答

0

您需要替換下一頁的基礎。可能的問題可能是%_%%#%,如果沒有測試,它似乎不太有用。但請嘗試下面的代碼,

$big = 999999999; // need an unlikely integer 
echo paginate_links(array(
    'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), 
    'format' => '/page/%#%', 
    'current' => $current_page, 
    'total' => $the_query->max_num_pages, 
    'show_all' => true, 
    'prev_text' => __('« PREV'), 
    'next_text' => __('NEXT »'), 
    'prev_next' => false, 
)); 

它可能會幫助你。也可以參考Paginate Links

+0

我測試過但沒有工作。 '.current'類在頁面1.不變。 –

+0

'$ current_page'在$'current_page = max(1,get_query_var('paged'))之後的值是多少?'是否遞增? –

+0

分頁更改其值,但不會將'.current'類更改爲另一個。 –