post_types->is_supported_post_type(); if ($post_type) { $result = [ 'strategy' => 'customizer', 'prefix' => $post_type ]; return $result; } if (function_exists('is_woocommerce')) { if (is_woocommerce()) { $result = [ 'strategy' => 'customizer', 'prefix' => 'woo' ]; return $result; } } $result = [ 'strategy' => 'customizer', 'prefix' => 'blog' ]; return $result; } } /** * Dispaly post pagination. * * @param array $args Pagination config. */ if (! function_exists('blocksy_display_posts_pagination')) { function blocksy_display_posts_pagination( $args = [] ) { $source = blocksy_get_pagination_source(); // Don't print empty markup if there's only one page. if (isset($args['source'])) { $source = $args['source']; } $args = wp_parse_args( $args, [ 'source' => $source, 'has_pagination' => true, 'pagination_type' => blocksy_akg_or_customizer( 'pagination_global_type', $source, 'simple' ), 'last_page_text' => __('No more posts to load', 'blocksy'), 'total_pages' => null, 'current_page' => null, 'format' => null, 'base' => null ] ); if ($source['prefix'] === 'woo') { $args['last_page_text'] = __('No more products to load', 'blocksy'); } if (! $args['has_pagination']) { return ''; } if (! $args['total_pages'] || !$args['current_page']) { global $wp_query, $wp_rewrite; $args['current_page'] = $wp_query->get('paged'); $args['total_pages'] = $wp_query->max_num_pages; if (! $args['current_page']) { $args['current_page'] = 1; } } if ($args['total_pages'] <= 1 ) { return ''; } $button_output = ''; if ( $args['pagination_type'] === 'load_more' && intval($args['current_page']) !== intval($args['total_pages']) ) { $label_button = blocksy_akg_or_customizer( 'load_more_label', $source, __('Load More', 'blocksy') ); $button_output = '' . $label_button . ''; } if ( $args['pagination_type'] !== 'simple' && $args['pagination_type'] !== 'next_prev' ) { if (intval($args['current_page']) === intval($args['total_pages'])) { return ''; } $button_output = '
' . $button_output; $button_output .= ''; $button_output .= '
' . $args['last_page_text'] . '
'; $button_output .= '
'; } $pagination_class = 'ct-pagination'; $divider_output = ''; $divider = blocksy_akg_or_customizer( 'paginationDivider', $source, [ 'width' => 1, 'style' => 'none', 'color' => [ 'color' => 'rgba(224, 229, 235, 0.5)', ] ] ); if ( $divider['style'] !== 'none' && $args['pagination_type'] !== 'infinite_scroll' ) { $divider_output = 'data-divider'; } $template = ' '; $paginate_links_args = [ 'mid_size' => 0, 'end_size' => 0, 'type' => 'array', 'total' => $args['total_pages'], 'current' => $args['current_page'], 'prev_text' => '' . __('Prev', 'blocksy'), 'next_text' => __('Next', 'blocksy') . ' ', ]; if ($args['format']) { $paginate_links_args['format'] = $args['format']; } if ($args['base']) { $paginate_links_args['base'] = $args['base']; } $links = paginate_links($paginate_links_args); $proper_links = $links; if ($args['pagination_type'] === 'next_prev') { $proper_links = []; foreach ($links as $link) { preg_match('/class="[^"]+"/', $link, $matches); if (count($matches) > 0) { if ( strpos($matches[0], 'next') !== false || strpos($matches[0], 'prev') !== false ) { $proper_links[] = $link; } } } } return sprintf( $template, join("\n", $proper_links), $button_output ); } }