wp_list_comments

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

List comments
Used in the comments.php template to list comments for a particular post

Parameters

  • string|array $args: Formatting options
  • array $comments: Optional array of comment objects. Defaults to $wp_query->comments

Source code

function wp_list_comments($args = array(), $comments = null ) {

	global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;



	$in_comment_loop = true;



	$comment_alt = $comment_thread_alt = 0;

	$comment_depth = 1;



	$defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all',

		'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '');



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



	// Figure out what comments we'll be looping through ($_comments)

	if ( null !== $comments ) {

		$comments = (array) $comments;

		if ( empty($comments) )

			return;

		if ( 'all' != $r['type'] ) {

			$comments_by_type = &separate_comments($comments);

			if ( empty($comments_by_type[$r['type']]) )

				return;

			$_comments = $comments_by_type[$r['type']];

		} else {

			$_comments = $comments;

		}

	} else {

		if ( empty($wp_query->comments) )

			return;

		if ( 'all' != $r['type'] ) {

			if ( empty($wp_query->comments_by_type) )

				$wp_query->comments_by_type = &separate_comments($wp_query->comments);

			if ( empty($wp_query->comments_by_type[$r['type']]) )

				return;

			$_comments = $wp_query->comments_by_type[$r['type']];

		} else {

			$_comments = $wp_query->comments;

		}

	}



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

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



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

		$r['per_page'] = 0;

		$r['page'] = 0;

	}



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

		if ( get_option('thread_comments') )

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

		else

			$r['max_depth'] = -1;

	}



	if ( '' === $r['page'] ) {

		if ( empty($overridden_cpage) ) {

			$r['page'] = get_query_var('cpage');

		} else {

			$threaded = ( -1 != $r['max_depth'] );

			$r['page'] = ( 'newest' == get_option('default_comments_page') ) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;

			set_query_var( 'cpage', $r['page'] );

		}

	}

	// Validation check

	$r['page'] = intval($r['page']);

	if ( 0 == $r['page'] && 0 != $r['per_page'] )

		$r['page'] = 1;



	if ( null === $r['reverse_top_level'] )

		$r['reverse_top_level'] = ( 'desc' == get_option('comment_order') );



	extract( $r, EXTR_SKIP );



	if ( empty($walker) )

		$walker = new Walker_Comment;



	$walker->paged_walk($_comments, $max_depth, $page, $per_page, $r);

	$wp_query->max_num_comment_pages = $walker->max_pages;



	$in_comment_loop = false;

}

3859

wp_list_cats

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

Parameters

  • string|array $args

Source code

function wp_list_cats($args = '') {

	_deprecated_function( __FUNCTION__, '2.1', 'wp_list_categories()' );



	$r = wp_parse_args( $args );



	// Map to new names.

	if ( isset($r['optionall']) && isset($r['all']))

		$r['show_option_all'] = $r['all'];

	if ( isset($r['sort_column']) )

		$r['orderby'] = $r['sort_column'];

	if ( isset($r['sort_order']) )

		$r['order'] = $r['sort_order'];

	if ( isset($r['optiondates']) )

		$r['show_last_update'] = $r['optiondates'];

	if ( isset($r['optioncount']) )

		$r['show_count'] = $r['optioncount'];

	if ( isset($r['list']) )

		$r['style'] = $r['list'] ? 'list' : 'break';

	$r['title_li'] = '';



	return wp_list_categories($r);

}

3857

wp_list_categories

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

Display or retrieve the HTML list of categories.
The list of arguments is below: ‘show_option_all’ (string) – Text to display for showing all categories. ‘orderby’ (string) default is ‘ID’ – What column to use for ordering the categories. ‘order’ (string) default is ‘ASC’ – What direction to order categories. ‘show_last_update’ (bool|int) default is 0 – See walk_category_dropdown_tree() ‘show_count’ (bool|int) default is 0 – Whether to show how many posts are in the category. ‘hide_empty’ (bool|int) default is 1 – Whether to hide categories that don’t have any posts attached to them. ‘use_desc_for_title’ (bool|int) default is 1 – Whether to use the description instead of the category title. ‘feed’ – See get_categories(). ‘feed_type’ – See get_categories(). ‘feed_image’ – See get_categories(). ‘child_of’ (int) default is 0 – See get_categories(). ‘exclude’ (string) – See get_categories(). ‘exclude_tree’ (string) – See get_categories(). ‘echo’ (bool|int) default is 1 – Whether to display or retrieve content. ‘current_category’ (int) – See get_categories(). ‘hierarchical’ (bool) – See get_categories(). ‘title_li’ (string) – See get_categories(). ‘depth’ (int) – The max depth.

Parameters

  • string|array $args: Optional. Override default arguments.

Return values

returns:HTML content only if ‘echo’ argument is 0.

Defined filters

  • wp_list_categories
    apply_filters( 'wp_list_categories', $output, $args )

Source code

function wp_list_categories( $args = '' ) {

	$defaults = array(

		'show_option_all' => '', 'show_option_none' => __('No categories'),

		'orderby' => 'name', 'order' => 'ASC',

		'show_last_update' => 0, 'style' => 'list',

		'show_count' => 0, 'hide_empty' => 1,

		'use_desc_for_title' => 1, 'child_of' => 0,

		'feed' => '', 'feed_type' => '',

		'feed_image' => '', 'exclude' => '',

		'exclude_tree' => '', 'current_category' => 0,

		'hierarchical' => true, 'title_li' => __( 'Categories' ),

		'echo' => 1, 'depth' => 0,

		'taxonomy' => 'category'

	);



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



	if ( !isset( $r['pad_counts'] ) && $r['show_count'] && $r['hierarchical'] )

		$r['pad_counts'] = true;



	if ( isset( $r['show_date'] ) )

		$r['include_last_update_time'] = $r['show_date'];



	if ( true == $r['hierarchical'] ) {

		$r['exclude_tree'] = $r['exclude'];

		$r['exclude'] = '';

	}



	if ( !isset( $r['class'] ) )

		$r['class'] = ( 'category' == $r['taxonomy'] ) ? 'categories' : $r['taxonomy'];



	extract( $r );



	if ( !taxonomy_exists($taxonomy) )

		return false;



	$categories = get_categories( $r );



	$output = '';

	if ( $title_li && 'list' == $style )

			$output = '<li class="' . esc_attr( $class ) . '">' . $title_li . '<ul>';



	if ( empty( $categories ) ) {

		if ( ! empty( $show_option_none ) ) {

			if ( 'list' == $style )

				$output .= '<li>' . $show_option_none . '</li>';

			else

				$output .= $show_option_none;

		}

	} else {

		if ( ! empty( $show_option_all ) ) {

			$posts_page = ( 'page' == get_option( 'show_on_front' ) && get_option( 'page_for_posts' ) ) ? get_permalink( get_option( 'page_for_posts' ) ) : home_url( '/' );

			$posts_page = esc_url( $posts_page );

			if ( 'list' == $style )

				$output .= "<li><a href='$posts_page'>$show_option_all</a></li>";

			else

				$output .= "<a href='$posts_page'>$show_option_all</a>";

		}



		if ( empty( $r['current_category'] ) && ( is_category() || is_tax() || is_tag() ) ) {

			$current_term_object = get_queried_object();

			if ( $r['taxonomy'] == $current_term_object->taxonomy )

				$r['current_category'] = get_queried_object_id();

		}



		if ( $hierarchical )

			$depth = $r['depth'];

		else

			$depth = -1; // Flat.



		$output .= walk_category_tree( $categories, $depth, $r );

	}



	if ( $title_li && 'list' == $style )

		$output .= '</ul></li>';



	$output = apply_filters( 'wp_list_categories', $output, $args );



	if ( $echo )

		echo $output;

	else

		return $output;

}

3855

wp_list_bookmarks

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

Retrieve or echo all of the bookmarks.
List of default arguments are as follows: ‘orderby’ – Default is ‘name’ (string). How to order the links by. String is based off of the bookmark scheme. ‘order’ – Default is ‘ASC’ (string). Either ‘ASC’ or ‘DESC’. Orders in either ascending or descending order. ‘limit’ – Default is -1 (integer) or show all. The amount of bookmarks to display. ‘category’ – Default is empty string (string). Include the links in what category ID(s). ‘category_name’ – Default is empty string (string). Get links by category name. ‘hide_invisible’ – Default is 1 (integer). Whether to show (default) or hide links marked as ‘invisible’. ‘show_updated’ – Default is 0 (integer). Will show the time of when the bookmark was last updated. ‘echo’ – Default is 1 (integer). Whether to echo (default) or return the formatted bookmarks. ‘categorize’ – Default is 1 (integer). Whether to show links listed by category (default) or show links in one column. ‘show_description’ – Default is 0 (integer). Whether to show the description of the bookmark.

Parameters

  • string|array $args: Optional. Overwrite the defaults of the function

Return values

returns:Will only return if echo option is set to not echo. Default is not return anything.

Defined filters

  • link_category
    apply_filters( "link_category", $cat->name )
  • wp_list_bookmarks
    apply_filters( 'wp_list_bookmarks', $output )

Source code

function wp_list_bookmarks($args = '') {

	$defaults = array(

		'orderby' => 'name', 'order' => 'ASC',

		'limit' => -1, 'category' => '', 'exclude_category' => '',

		'category_name' => '', 'hide_invisible' => 1,

		'show_updated' => 0, 'echo' => 1,

		'categorize' => 1, 'title_li' => __('Bookmarks'),

		'title_before' => '<h2>', 'title_after' => '</h2>',

		'category_orderby' => 'name', 'category_order' => 'ASC',

		'class' => 'linkcat', 'category_before' => '<li id="%id" class="%class">',

		'category_after' => '</li>'

	);



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

	extract( $r, EXTR_SKIP );



	$output = '';



	if ( $categorize ) {

		//Split the bookmarks into ul's for each category

		$cats = get_terms('link_category', array('name__like' => $category_name, 'include' => $category, 'exclude' => $exclude_category, 'orderby' => $category_orderby, 'order' => $category_order, 'hierarchical' => 0));



		foreach ( (array) $cats as $cat ) {

			$params = array_merge($r, array('category'=>$cat->term_id));

			$bookmarks = get_bookmarks($params);

			if ( empty($bookmarks) )

				continue;

			$output .= str_replace(array('%id', '%class'), array("linkcat-$cat->term_id", $class), $category_before);

			$catname = apply_filters( "link_category", $cat->name );

			$output .= "$title_before$catname$title_after\n\t<ul class='xoxo blogroll'>\n";

			$output .= _walk_bookmarks($bookmarks, $r);

			$output .= "\n\t</ul>\n$category_after\n";

		}

	} else {

		//output one single list using title_li for the title

		$bookmarks = get_bookmarks($r);



		if ( !empty($bookmarks) ) {

			if ( !empty( $title_li ) ){

				$output .= str_replace(array('%id', '%class'), array("linkcat-$category", $class), $category_before);

				$output .= "$title_before$title_li$title_after\n\t<ul class='xoxo blogroll'>\n";

				$output .= _walk_bookmarks($bookmarks, $r);

				$output .= "\n\t</ul>\n$category_after\n";

			} else {

				$output .= _walk_bookmarks($bookmarks, $r);

			}

		}

	}



	$output = apply_filters( 'wp_list_bookmarks', $output );



	if ( !$echo )

		return $output;

	echo $output;

}

3853

wp_list_authors

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

List all the authors of the blog, with several options available.

Parameters

  • array $args: The argument array.

Return values

returns:The output, if echo is set to false.

Source code

function wp_list_authors($args = '') {

	global $wpdb;



	$defaults = array(

		'orderby' => 'name', 'order' => 'ASC', 'number' => '',

		'optioncount' => false, 'exclude_admin' => true,

		'show_fullname' => false, 'hide_empty' => true,

		'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true,

		'style' => 'list', 'html' => true

	);



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

	extract( $args, EXTR_SKIP );



	$return = '';



	$query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number' ) );

	$query_args['fields'] = 'ids';

	$authors = get_users( $query_args );



	$author_count = array();

	foreach ( (array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author") as $row )

		$author_count[$row->post_author] = $row->count;



	foreach ( $authors as $author_id ) {

		$author = get_userdata( $author_id );



		if ( $exclude_admin && 'admin' == $author->display_name )

			continue;



		$posts = isset( $author_count[$author->ID] ) ? $author_count[$author->ID] : 0;



		if ( !$posts && $hide_empty )

			continue;



		$link = '';



		if ( $show_fullname && $author->first_name && $author->last_name )

			$name = "$author->first_name $author->last_name";

		else

			$name = $author->display_name;



		if ( !$html ) {

			$return .= $name . ', ';



			continue; // No need to go further to process HTML.

		}



		if ( 'list' == $style ) {

			$return .= '<li>';

		}



		$link = '<a href="' . get_author_posts_url( $author->ID, $author->user_nicename ) . '" title="' . esc_attr( sprintf(__("Posts by %s"), $author->display_name) ) . '">' . $name . '</a>';



		if ( !empty( $feed_image ) || !empty( $feed ) ) {

			$link .= ' ';

			if ( empty( $feed_image ) ) {

				$link .= '(';

			}



			$link .= '<a href="' . get_author_feed_link( $author->ID ) . '"';



			$alt = $title = '';

			if ( !empty( $feed ) ) {

				$title = ' title="' . esc_attr( $feed ) . '"';

				$alt = ' alt="' . esc_attr( $feed ) . '"';

				$name = $feed;

				$link .= $title;

			}



			$link .= '>';



			if ( !empty( $feed_image ) )

				$link .= '<img src="' . esc_url( $feed_image ) . '" style="border: none;"' . $alt . $title . ' />';

			else

				$link .= $name;



			$link .= '</a>';



			if ( empty( $feed_image ) )

				$link .= ')';

		}



		if ( $optioncount )

			$link .= ' ('. $posts . ')';



		$return .= $link;

		$return .= ( 'list' == $style ) ? '</li>' : ', ';

	}



	$return = rtrim($return, ', ');



	if ( !$echo )

		return $return;



	echo $return;

}

3851