parent_dropdown

Definition:
function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {}

Parameters

  • unknown_type $default
  • unknown_type $parent
  • unknown_type $level

Source code

function parent_dropdown( $default = 0, $parent = 0, $level = 0 ) {

	global $wpdb, $post_ID;

	$items = $wpdb->get_results( $wpdb->prepare("SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' ORDER BY menu_order", $parent) );



	if ( $items ) {

		foreach ( $items as $item ) {

			// A page cannot be its own parent.

			if (!empty ( $post_ID ) ) {

				if ( $item->ID == $post_ID ) {

					continue;

				}

			}

			$pad = str_repeat( ' ', $level * 3 );

			if ( $item->ID == $default)

				$current = ' selected="selected"';

			else

				$current = '';



			echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad " . esc_html($item->post_title) . "</option>";

			parent_dropdown( $default, $item->ID, $level +1 );

		}

	} else {

		return false;

	}

}

2479

paginate_links

Definition:
function paginate_links( $args = '' ) {}

Retrieve paginated link for archive post pages.
Technically, the function can be used to create paginated link list for any area. The ‘base’ argument is used to reference the url, which will be used to create the paginated links. The ‘format’ argument is then used for replacing the page number. It is however, most likely and by default, to be used on the archive post pages.

Parameters

  • string|array $args: Optional. Override defaults.

Return values

returns:String of page links or array of page links.

Defined filters

  • paginate_links
    apply_filters( 'paginate_links', $link )
  • paginate_links
    apply_filters( 'paginate_links', $link )
  • paginate_links
    apply_filters( 'paginate_links', $link )

Source code

function paginate_links( $args = '' ) {

	$defaults = array(

		'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below)

		'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number

		'total' => 1,

		'current' => 0,

		'show_all' => false,

		'prev_next' => true,

		'prev_text' => __('&laquo; Previous'),

		'next_text' => __('Next &raquo;'),

		'end_size' => 1,

		'mid_size' => 2,

		'type' => 'plain',

		'add_args' => false, // array of query args to add

		'add_fragment' => ''

	);



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

	extract($args, EXTR_SKIP);



	// Who knows what else people pass in $args

	$total = (int) $total;

	if ( $total < 2 )

		return;

	$current  = (int) $current;

	$end_size = 0  < (int) $end_size ? (int) $end_size : 1; // Out of bounds?  Make it the default.

	$mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2;

	$add_args = is_array($add_args) ? $add_args : false;

	$r = '';

	$page_links = array();

	$n = 0;

	$dots = false;



	if ( $prev_next && $current && 1 < $current ) :

		$link = str_replace('%_%', 2 == $current ? '' : $format, $base);

		$link = str_replace('%#%', $current - 1, $link);

		if ( $add_args )

			$link = add_query_arg( $add_args, $link );

		$link .= $add_fragment;

		$page_links[] = '<a class="prev page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $prev_text . '</a>';

	endif;

	for ( $n = 1; $n <= $total; $n++ ) :

		$n_display = number_format_i18n($n);

		if ( $n == $current ) :

			$page_links[] = "<span class='page-numbers current'>$n_display</span>";

			$dots = true;

		else :

			if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :

				$link = str_replace('%_%', 1 == $n ? '' : $format, $base);

				$link = str_replace('%#%', $n, $link);

				if ( $add_args )

					$link = add_query_arg( $add_args, $link );

				$link .= $add_fragment;

				$page_links[] = "<a class='page-numbers' href='" . esc_url( apply_filters( 'paginate_links', $link ) ) . "'>$n_display</a>";

				$dots = true;

			elseif ( $dots && !$show_all ) :

				$page_links[] = '<span class="page-numbers dots">' . __( '&hellip;' ) . '</span>';

				$dots = false;

			endif;

		endif;

	endfor;

	if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) :

		$link = str_replace('%_%', $format, $base);

		$link = str_replace('%#%', $current + 1, $link);

		if ( $add_args )

			$link = add_query_arg( $add_args, $link );

		$link .= $add_fragment;

		$page_links[] = '<a class="next page-numbers" href="' . esc_url( apply_filters( 'paginate_links', $link ) ) . '">' . $next_text . '</a>';

	endif;

	switch ( $type ) :

		case 'array' :

			return $page_links;

			break;

		case 'list' :

			$r .= "<ul class='page-numbers'>\n\t<li>";

			$r .= join("</li>\n\t<li>", $page_links);

			$r .= "</li>\n</ul>\n";

			break;

		default :

			$r = join("\n", $page_links);

			break;

	endswitch;

	return $r;

}

2477

paginate_comments_links

Definition:
function paginate_comments_links($args = array() {}

Create pagination links for the comments on the current post.

Parameters

  • string|array $args: Optional args. See paginate_links().

Return values

returns:Markup for pagination links.

Source code

function paginate_comments_links($args = array()) {

	global $wp_rewrite;



	if ( !is_singular() || !get_option('page_comments') )

		return;



	$page = get_query_var('cpage');

	if ( !$page )

		$page = 1;

	$max_page = get_comment_pages_count();

	$defaults = array(

		'base' => add_query_arg( 'cpage', '%#%' ),

		'format' => '',

		'total' => $max_page,

		'current' => $page,

		'echo' => true,

		'add_fragment' => '#comments'

	);

	if ( $wp_rewrite->using_permalinks() )

		$defaults['base'] = user_trailingslashit(trailingslashit(get_permalink()) . 'comment-page-%#%', 'commentpaged');



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

	$page_links = paginate_links( $args );



	if ( $args['echo'] )

		echo $page_links;

	else

		return $page_links;

}

2475

page_template_dropdown

Definition:
function page_template_dropdown( $default = '' ) {}

Parameters

  • unknown_type $default

Source code

function page_template_dropdown( $default = '' ) {

	$templates = get_page_templates();

	ksort( $templates );

	foreach (array_keys( $templates ) as $template )

		: if ( $default == $templates[$template] )

			$selected = " selected='selected'";

		else

			$selected = '';

	echo "\n\t<option value='".$templates[$template]."' $selected>$template</option>";

	endforeach;

}

2473

page_rows

Definition:
function page_rows($pages, $pagenum = 1, $per_page = 20) {}

Parameters

  • unknown_type $pages
  • unknown_type $pagenum
  • unknown_type $per_page

Source code

function page_rows($pages, $pagenum = 1, $per_page = 20) {

	global $wpdb;



	$level = 0;



	if ( ! $pages ) {

		$pages = get_pages( array('sort_column' => 'menu_order') );



		if ( ! $pages )

			return false;

	}



	/*

	 * arrange pages into two parts: top level pages and children_pages

	 * children_pages is two dimensional array, eg.

	 * children_pages[10][] contains all sub-pages whose parent is 10.

	 * It only takes O(N) to arrange this and it takes O(1) for subsequent lookup operations

	 * If searching, ignore hierarchy and treat everything as top level

	 */

	if ( empty($_GET['s']) ) {



		$top_level_pages = array();

		$children_pages = array();



		foreach ( $pages as $page ) {



			// catch and repair bad pages

			if ( $page->post_parent == $page->ID ) {

				$page->post_parent = 0;

				$wpdb->update($wpdb->posts, array('post_parent' => 0), array('ID' => $page->ID));

				clean_page_cache( $page->ID );

			}



			if ( 0 == $page->post_parent )

				$top_level_pages[] = $page;

			else

				$children_pages[ $page->post_parent ][] = $page;

		}



		$pages = &$top_level_pages;

	}



	$count = 0;

	$start = ($pagenum - 1) * $per_page;

	$end = $start + $per_page;



	foreach ( $pages as $page ) {

		if ( $count >= $end )

			break;



		if ( $count >= $start )

			echo "\t" . display_page_row( $page, $level );



		$count++;



		if ( isset($children_pages) )

			_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page );

	}



	// if it is the last pagenum and there are orphaned pages, display them with paging as well

	if ( isset($children_pages) && $count < $end ){

		foreach( $children_pages as $orphans ){

			foreach ( $orphans as $op ) {

				if ( $count >= $end )

					break;

				if ( $count >= $start )

					echo "\t" . display_page_row( $op, 0 );

				$count++;

			}

		}

	}

}

2471