Created
March 1, 2020 12:44
-
-
Save kmaroff/b6c4196890fc8f54867aac67de95e6a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Если не работает пагинация | |
| add_filter('redirect_canonical', 'my_redirect_canonical', 10, 2); | |
| function my_redirect_canonical($redirect_url, $requested_url) { | |
| $do_redirect = true; | |
| if(preg_match('/page/',$requested_url)){ | |
| $do_redirect = false; | |
| } | |
| return $do_redirect; | |
| } | |
| //Если не работает пагинация вариант 2, если первый не работает | |
| add_filter('redirect_canonical','pif_disable_redirect_canonical'); | |
| function pif_disable_redirect_canonical($redirect_url) { | |
| if( is_singular() && in_category('PLACE CAT ID HERE') ) { | |
| $redirect_url = false; | |
| } | |
| return $redirect_url; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $gallery = get_field('field_59f2a1869ef2b'); | |
| $images = array(); | |
| $items_per_page = 4; | |
| $total_items = count($gallery); | |
| $size = 'full'; | |
| $total_pages = ceil($total_items / $items_per_page); | |
| if(get_query_var('paged')){ | |
| $current_page = get_query_var('paged'); | |
| } | |
| elseif (get_query_var('page')) { | |
| $current_page = get_query_var('page'); | |
| } | |
| else{ | |
| $current_page = 1; | |
| } | |
| $starting_point = (($current_page-1)*$items_per_page); | |
| if($gallery){ | |
| $images = array_slice($gallery,$starting_point,$items_per_page); | |
| } | |
| if(!empty($images)){ | |
| foreach( $images as $image ): | |
| echo wp_get_attachment_image( $image['ID'], $size ); | |
| endforeach; | |
| } | |
| $big = 999999999; | |
| echo paginate_links(array( | |
| 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), | |
| 'format' => '?paged=%#%', | |
| 'current' => $current_page, | |
| 'total' => $total_pages, | |
| 'before_page_number' => '<span class="screen-reader-text">'.$translated.' </span>' | |
| )); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment