get_page_template

Definition:
function get_page_template() {}

Retrieve path of page template in current or parent template.
Will first look for the specifically assigned page template The will search for ‘page-{slug}.php’ followed by ‘page-id.php’ and finally ‘page.php’

Source code

function get_page_template() {

	$id = get_queried_object_id();

	$template = get_post_meta($id, '_wp_page_template', true);

	$pagename = get_query_var('pagename');



	if ( !$pagename && $id > 0 ) {

		// If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object

		$post = get_queried_object();

		$pagename = $post->post_name;

	}



	if ( 'default' == $template )

		$template = '';



	$templates = array();

	if ( !empty($template) && !validate_file($template) )

		$templates[] = $template;

	if ( $pagename )

		$templates[] = "page-$pagename.php";

	if ( $id )

		$templates[] = "page-$id.php";

	$templates[] = 'page.php';



	return get_query_template( 'page', $templates );

}

1544

get_page_statuses

Definition:
function get_page_statuses( ) {}

Retrieve all of the WordPress support page statuses.
Pages have a limited set of valid status values, this provides the post_status values and descriptions.

Return values

returns:List of page statuses.

Source code

function get_page_statuses( ) {

	$status = array(

		'draft'			=> __('Draft'),

		'private'		=> __('Private'),

		'publish'		=> __('Published')

	);



	return $status;

}

1542

get_page_of_comment

Definition:
function get_page_of_comment( $comment_ID, $args = array() {}

Calculate what page number a comment will appear on for comment paging.

Parameters

  • int $comment_ID: Comment ID.
  • array $args: Optional args.

Return values

returns:Comment page number or null on error.

Source code

function get_page_of_comment( $comment_ID, $args = array() ) {

	global $wpdb;



	if ( !$comment = get_comment( $comment_ID ) )

		return;



	$defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' );

	$args = wp_parse_args( $args, $defaults );



	if ( '' === $args['per_page'] && get_option('page_comments') )

		$args['per_page'] = get_query_var('comments_per_page');

	if ( empty($args['per_page']) ) {

		$args['per_page'] = 0;

		$args['page'] = 0;

	}

	if ( $args['per_page'] < 1 )

		return 1;



	if ( '' === $args['max_depth'] ) {

		if ( get_option('thread_comments') )

			$args['max_depth'] = get_option('thread_comments_depth');

		else

			$args['max_depth'] = -1;

	}



	// Find this comment's top level parent if threading is enabled

	if ( $args['max_depth'] > 1 && 0 != $comment->comment_parent )

		return get_page_of_comment( $comment->comment_parent, $args );



	$allowedtypes = array(

		'comment' => '',

		'pingback' => 'pingback',

		'trackback' => 'trackback',

	);



	$comtypewhere = ( 'all' != $args['type'] && isset($allowedtypes[$args['type']]) ) ? " AND comment_type = '" . $allowedtypes[$args['type']] . "'" : '';



	// Count comments older than this one

	$oldercoms = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = 0 AND comment_approved = '1' AND comment_date_gmt < '%s'" . $comtypewhere, $comment->comment_post_ID, $comment->comment_date_gmt ) );



	// No older comments? Then it's page #1.

	if ( 0 == $oldercoms )

		return 1;



	// Divide comments older than this one by comments per page to get this comment's page number

	return ceil( ( $oldercoms + 1 ) / $args['per_page'] );

}

1540

get_page_link

Definition:
function get_page_link( $id = false, $leavename = false, $sample = false ) {}

Retrieve the permalink for current page or page ID.
Respects page_on_front. Use this one.

Parameters

  • int $id: Optional. Post ID.
  • bool $leavename: Optional, defaults to false. Whether to keep page name.
  • bool $sample: Optional, defaults to false. Is it a sample permalink.

Defined filters

  • page_link
    apply_filters('page_link', $link, $id, $sample)

Source code

function get_page_link( $id = false, $leavename = false, $sample = false ) {

	global $post;



	$id = (int) $id;

	if ( !$id )

		$id = (int) $post->ID;



	if ( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') )

		$link = home_url('/');

	else

		$link = _get_page_link( $id , $leavename, $sample );



	return apply_filters('page_link', $link, $id, $sample);

}

1538

get_page_hierarchy

Definition:
function &get_page_hierarchy( &$pages, $page_id = 0 ) {}

Order the pages with children under parents in a flat list.
It uses auxiliary structure to hold parent-children relationships and runs in O(N) complexity

Parameters

  • array $pages: Posts array.
  • int $page_id: Parent page ID.
  • &$pages

Return values

returns:A list arranged by hierarchy. Children immediately follow their parents.

Source code

function &get_page_hierarchy( &$pages, $page_id = 0 ) {

	if ( empty( $pages ) ) {

		$result = array();

		return $result;

	}



	$children = array();

	foreach ( (array) $pages as $p ) {

		$parent_id = intval( $p->post_parent );

		$children[ $parent_id ][] = $p;

	}



	$result = array();

	_page_traverse_name( $page_id, $children, $result );



	return $result;

}

1536