Function Reference: geodir_pagination

Summary

Returns paginated HTML string based on the given parameters.

Global Values

$wpdb
(object) (required) WordPress Database object.

Default: None
$wp_query
(object) (required) WordPress Query object.

Default: None

Package

GeoDirectory

Parameters

$before
(string) (required) The HTML to prepend.

Default: None
$after
(string) (required) The HTML to append.

Default: None
$prelabel
(string) (required) The previous link label.

Default: None
$nxtlabel
(string) (required) The next link label.

Default: None
$pages_to_show
(int) (required) Number of pages to display on the pagination.

Default: : 5
$always_show
(bool) (required) Do you want to show the pagination always? Default: false.

Default: None

Change Log

Since: 1.0.0

1.5.5 Fixed pagination links when location selected.

Filters

‘geodir_pagination_advance_info’ [Line: 445]

Source File

geodir_pagination() is located in geodirectory_template_tags.php [Line: 362]

Source Code

function geodir_pagination($before = '', $after = '', $prelabel = '', $nxtlabel = '', $pages_to_show = 5, $always_show = false) {
    global $wp_query, $posts_per_page, $wpdb, $paged, $blog_id;

    if (empty($prelabel)) {
        $prelabel = '<';
    }

    if (empty($nxtlabel)) {
        $nxtlabel = '>';
    }

    $half_pages_to_show = round($pages_to_show / 2);

    if (geodir_is_page('home')) // dont apply default  pagination for geodirectory home page.
        return;

    if (!is_single()) {
        if (function_exists('geodir_location_geo_home_link')) {
            remove_filter('home_url', 'geodir_location_geo_home_link', 100000);
        }
        $numposts = $wp_query->found_posts;

        $max_page = ceil($numposts / $posts_per_page);

        if (empty($paged)) {
            $paged = 1;
        }
        
        $post_type = geodir_get_current_posttype();
        $listing_type_name = get_post_type_plural_label($post_type);
        if (geodir_is_page('listing') || geodir_is_page('search')) {            
            $term = array();
            
            if (is_tax()) {
                $term_id = get_queried_object_id();
                $taxonomy = get_query_var('taxonomy');

                if ($term_id && $post_type && get_query_var('taxonomy') == $post_type . 'category' ) {
                    $term = get_term($term_id, $post_type . 'category');
                }
            }
            
            if (geodir_is_page('search') && !empty($_REQUEST['s' . $post_type . 'category'])) {
                $taxonomy_search = $_REQUEST['s' . $post_type . 'category'];
                
                if (!is_array($taxonomy_search)) {
                    $term = get_term((int)$taxonomy_search, $post_type . 'category');
                } else if(is_array($taxonomy_search) && count($taxonomy_search) == 1) { // single category search
                    $term = get_term((int)$taxonomy_search[0], $post_type . 'category');
                }
            }
            
            if (!empty($term) && !is_wp_error($term)) {
                $listing_type_name = $term->name;
            }
        }

        if ($max_page > 1 || $always_show) {            
            // Extra pagination info
            $geodir_pagination_more_info = get_option('geodir_pagination_advance_info');
            $start_no = ( $paged - 1 ) * $posts_per_page + 1;
            $end_no = min($paged * $posts_per_page, $numposts);

            if ($geodir_pagination_more_info != '') {
                if ($listing_type_name) {
                    $listing_type_name = __($listing_type_name, 'geodirectory');
                    $pegination_desc = wp_sprintf(__('Showing %s %d-%d of %d', 'geodirectory'), $listing_type_name, $start_no, $end_no, $numposts);
                } else {
                    $pegination_desc = wp_sprintf(__('Showing listings %d-%d of %d', 'geodirectory'), $start_no, $end_no, $numposts);
                }
                $pagination_info = '
' . $pegination_desc . '
'; /** * Adds an extra pagination info above/under pagination. * * @since 1.5.9 * * @param string $pagination_info Extra pagination info content. * @param string $listing_type_name Listing results type. * @param string $start_no First result number. * @param string $end_no Last result number. * @param string $numposts Total number of listings. * @param string $post_type The post type. */ $pagination_info = apply_filters('geodir_pagination_advance_info', $pagination_info, $listing_type_name, $start_no, $end_no, $numposts, $post_type); if ($geodir_pagination_more_info == 'before') { $before = $before . $pagination_info; } else if ($geodir_pagination_more_info == 'after') { $after = $pagination_info . $after; } } echo "$before $after"; } if (function_exists('geodir_location_geo_home_link')) { add_filter('home_url', 'geodir_location_geo_home_link', 100000, 2); } } }