get_pagenum_link

Definition:
function get_pagenum_link($pagenum = 1) {}

Retrieve links for page numbers.

Parameters

  • int $pagenum: Optional. Page ID.

Defined filters

  • get_pagenum_link
    apply_filters('get_pagenum_link', $result)

Source code

function get_pagenum_link($pagenum = 1) {

	global $wp_rewrite;



	$pagenum = (int) $pagenum;



	$request = remove_query_arg( 'paged' );



	$home_root = parse_url(home_url());

	$home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';

	$home_root = preg_quote( trailingslashit( $home_root ), '|' );



	$request = preg_replace('|^'. $home_root . '|', '', $request);

	$request = preg_replace('|^/+|', '', $request);



	if ( !$wp_rewrite->using_permalinks() || is_admin() ) {

		$base = trailingslashit( get_bloginfo( 'url' ) );



		if ( $pagenum > 1 ) {

			$result = add_query_arg( 'paged', $pagenum, $base . $request );

		} else {

			$result = $base . $request;

		}

	} else {

		$qs_regex = '|\?.*?$|';

		preg_match( $qs_regex, $request, $qs_match );



		if ( !empty( $qs_match[0] ) ) {

			$query_string = $qs_match[0];

			$request = preg_replace( $qs_regex, '', $request );

		} else {

			$query_string = '';

		}



		$request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request);

		$request = preg_replace( '|^index\.php|', '', $request);

		$request = ltrim($request, '/');



		$base = trailingslashit( get_bloginfo( 'url' ) );



		if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) )

			$base .= 'index.php/';



		if ( $pagenum > 1 ) {

			$request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . "/" . $pagenum, 'paged' );

		}



		$result = $base . $request . $query_string;

	}



	$result = apply_filters('get_pagenum_link', $result);



	return $result;

}

1526

About these ads

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 150 other followers

%d bloggers like this: