+ }
+
+ // If there's a category or tag
+ if ( is_category() || is_tag() ) {
+ $title = single_term_title( '', false );
+ }
+
+ // If there's a taxonomy
+ if ( is_tax() ) {
+ $term = get_queried_object();
+ if ( $term ) {
+ $tax = get_taxonomy( $term->taxonomy );
+ $title = single_term_title( $tax->labels->name . $t_sep, false );
+ }
+ }
+
+ // If there's an author
+ if ( is_author() && ! is_post_type_archive() ) {
+ $author = get_queried_object();
+ if ( $author ) {
+ $title = $author->display_name;
+ }
+ }
+
+ // Post type archives with has_archive should override terms.
+ if ( is_post_type_archive() && $post_type_object->has_archive ) {
+ $title = post_type_archive_title( '', false );
+ }
+
+ // If there's a month
+ if ( is_archive() && ! empty( $m ) ) {
+ $my_year = substr( $m, 0, 4 );
+ $my_month = $wp_locale->get_month( substr( $m, 4, 2 ) );
+ $my_day = intval( substr( $m, 6, 2 ) );
+ $title = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' );
+ }
+
+ // If there's a year
+ if ( is_archive() && ! empty( $year ) ) {
+ $title = $year;
+ if ( ! empty( $monthnum ) ) {
+ $title .= $t_sep . $wp_locale->get_month( $monthnum );
+ }
+ if ( ! empty( $day ) ) {
+ $title .= $t_sep . zeroise( $day, 2 );
+ }
+ }
+
+ // If it's a search
+ if ( is_search() ) {
+ /* translators: 1: separator, 2: search phrase */
+ $title = sprintf( __( 'Search Results %1$s %2$s' ), $t_sep, strip_tags( $search ) );
+ }
+
+ // If it's a 404 page
+ if ( is_404() ) {
+ $title = __( 'Page not found' );
+ }
+
+ $prefix = '';
+ if ( ! empty( $title ) ) {
+ $prefix = " $sep ";
+ }
+
+ /**
+ * Filters the parts of the page title.
+ *
+ * @since 4.0.0
+ *
+ * @param array $title_array Parts of the page title.
+ */
+ $title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) );
+
+ // Determines position of the separator and direction of the breadcrumb
+ if ( 'right' == $seplocation ) { // sep on right, so reverse the order
+ $title_array = array_reverse( $title_array );
+ $title = implode( " $sep ", $title_array ) . $prefix;
+ } else {
+ $title = $prefix . implode( " $sep ", $title_array );
+ }
+
+ /**
+ * Filters the text of the page title.
+ *
+ * @since 2.0.0
+ *
+ * @param string $title Page title.
+ * @param string $sep Title separator.
+ * @param string $seplocation Location of the separator (left or right).
+ */
+ $title = apply_filters( 'wp_title', $title, $sep, $seplocation );
+
+ // Send it out
+ if ( $display ) {
+ echo $title;
+ } else {
+ return $title;
+ }
+}
+
+/**
+ * Display or retrieve page title for post.
+ *
+ * This is optimized for single.php template file for displaying the post title.
+ *
+ * It does not support placing the separator after the title, but by leaving the
+ * prefix parameter empty, you can set the title separator manually. The prefix
+ * does not automatically place a space between the prefix, so if there should
+ * be a space, the parameter value will need to have it at the end.
+ *
+ * @since 0.71
+ *
+ * @param string $prefix Optional. What to display before the title.
+ * @param bool $display Optional, default is true. Whether to display or retrieve title.
+ * @return string|void Title when retrieving.
+ */
+function single_post_title( $prefix = '', $display = true ) {
+ $_post = get_queried_object();
+
+ if ( !isset($_post->post_title) )
+ return;
+
+ /**
+ * Filters the page title for a single post.
+ *
+ * @since 0.71
+ *
+ * @param string $_post_title The single post page title.
+ * @param object $_post The current queried object as returned by get_queried_object().
+ */
+ $title = apply_filters( 'single_post_title', $_post->post_title, $_post );
+ if ( $display )
+ echo $prefix . $title;
+ else
+ return $prefix . $title;
+}
+
+/**
+ * Display or retrieve title for a post type archive.
+ *
+ * This is optimized for archive.php and archive-{$post_type}.php template files
+ * for displaying the title of the post type.
+ *
+ * @since 3.1.0
+ *
+ * @param string $prefix Optional. What to display before the title.
+ * @param bool $display Optional, default is true. Whether to display or retrieve title.
+ * @return string|void Title when retrieving, null when displaying or failure.
+ */
+function post_type_archive_title( $prefix = '', $display = true ) {
+ if ( ! is_post_type_archive() )
+ return;
+
+ $post_type = get_query_var( 'post_type' );
+ if ( is_array( $post_type ) )
+ $post_type = reset( $post_type );
+
+ $post_type_obj = get_post_type_object( $post_type );
+
+ /**
+ * Filters the post type archive title.
+ *
+ * @since 3.1.0
+ *
+ * @param string $post_type_name Post type 'name' label.
+ * @param string $post_type Post type.
+ */
+ $title = apply_filters( 'post_type_archive_title', $post_type_obj->labels->name, $post_type );
+
+ if ( $display )
+ echo $prefix . $title;
+ else
+ return $prefix . $title;
+}
+
+/**
+ * Display or retrieve page title for category archive.
+ *
+ * Useful for category template files for displaying the category page title.
+ * The prefix does not automatically place a space between the prefix, so if
+ * there should be a space, the parameter value will need to have it at the end.
+ *
+ * @since 0.71
+ *
+ * @param string $prefix Optional. What to display before the title.
+ * @param bool $display Optional, default is true. Whether to display or retrieve title.
+ * @return string|void Title when retrieving.
+ */
+function single_cat_title( $prefix = '', $display = true ) {
+ return single_term_title( $prefix, $display );
+}
+
+/**
+ * Display or retrieve page title for tag post archive.
+ *
+ * Useful for tag template files for displaying the tag page title. The prefix
+ * does not automatically place a space between the prefix, so if there should
+ * be a space, the parameter value will need to have it at the end.
+ *
+ * @since 2.3.0
+ *
+ * @param string $prefix Optional. What to display before the title.
+ * @param bool $display Optional, default is true. Whether to display or retrieve title.
+ * @return string|void Title when retrieving.
+ */
+function single_tag_title( $prefix = '', $display = true ) {
+ return single_term_title( $prefix, $display );
+}
+
+/**
+ * Display or retrieve page title for taxonomy term archive.
+ *
+ * Useful for taxonomy term template files for displaying the taxonomy term page title.
+ * The prefix does not automatically place a space between the prefix, so if there should
+ * be a space, the parameter value will need to have it at the end.
+ *
+ * @since 3.1.0
+ *
+ * @param string $prefix Optional. What to display before the title.
+ * @param bool $display Optional, default is true. Whether to display or retrieve title.
+ * @return string|void Title when retrieving.
+ */
+function single_term_title( $prefix = '', $display = true ) {
+ $term = get_queried_object();
+
+ if ( !$term )
+ return;
+
+ if ( is_category() ) {
+ /**
+ * Filters the category archive page title.
+ *
+ * @since 2.0.10
+ *
+ * @param string $term_name Category name for archive being displayed.
+ */
+ $term_name = apply_filters( 'single_cat_title', $term->name );
+ } elseif ( is_tag() ) {
+ /**
+ * Filters the tag archive page title.
+ *
+ * @since 2.3.0
+ *
+ * @param string $term_name Tag name for archive being displayed.
+ */
+ $term_name = apply_filters( 'single_tag_title', $term->name );
+ } elseif ( is_tax() ) {
+ /**
+ * Filters the custom taxonomy archive page title.
+ *
+ * @since 3.1.0
+ *
+ * @param string $term_name Term name for archive being displayed.
+ */
+ $term_name = apply_filters( 'single_term_title', $term->name );
+ } else {
+ return;
+ }
+
+ if ( empty( $term_name ) )
+ return;
+
+ if ( $display )
+ echo $prefix . $term_name;
+ else
+ return $prefix . $term_name;
+}
+
+/**
+ * Display or retrieve page title for post archive based on date.
+ *
+ * Useful for when the template only needs to display the month and year,
+ * if either are available. The prefix does not automatically place a space
+ * between the prefix, so if there should be a space, the parameter value
+ * will need to have it at the end.
+ *
+ * @since 0.71
+ *
+ * @global WP_Locale $wp_locale
+ *
+ * @param string $prefix Optional. What to display before the title.
+ * @param bool $display Optional, default is true. Whether to display or retrieve title.
+ * @return string|void Title when retrieving.
+ */
+function single_month_title($prefix = '', $display = true ) {
+ global $wp_locale;
+
+ $m = get_query_var('m');
+ $year = get_query_var('year');
+ $monthnum = get_query_var('monthnum');
+
+ if ( !empty($monthnum) && !empty($year) ) {
+ $my_year = $year;
+ $my_month = $wp_locale->get_month($monthnum);
+ } elseif ( !empty($m) ) {
+ $my_year = substr($m, 0, 4);
+ $my_month = $wp_locale->get_month(substr($m, 4, 2));
+ }
+
+ if ( empty($my_month) )
+ return false;
+
+ $result = $prefix . $my_month . $prefix . $my_year;
+
+ if ( !$display )
+ return $result;
+ echo $result;
+}
+
+/**
+ * Display the archive title based on the queried object.
+ *
+ * @since 4.1.0
+ *
+ * @see get_the_archive_title()
+ *
+ * @param string $before Optional. Content to prepend to the title. Default empty.
+ * @param string $after Optional. Content to append to the title. Default empty.
+ */
+function the_archive_title( $before = '', $after = '' ) {
+ $title = get_the_archive_title();
+
+ if ( ! empty( $title ) ) {
+ echo $before . $title . $after;
+ }
+}
+
+/**
+ * Retrieve the archive title based on the queried object.
+ *
+ * @since 4.1.0
+ *
+ * @return string Archive title.
+ */
+function get_the_archive_title() {
+ if ( is_category() ) {
+ /* translators: Category archive title. 1: Category name */
+ $title = sprintf( __( 'Category: %s' ), single_cat_title( '', false ) );
+ } elseif ( is_tag() ) {
+ /* translators: Tag archive title. 1: Tag name */
+ $title = sprintf( __( 'Tag: %s' ), single_tag_title( '', false ) );
+ } elseif ( is_author() ) {
+ /* translators: Author archive title. 1: Author name */
+ $title = sprintf( __( 'Author: %s' ), '<span class="vcard">' . get_the_author() . '</span>' );
+ } elseif ( is_year() ) {
+ /* translators: Yearly archive title. 1: Year */
+ $title = sprintf( __( 'Year: %s' ), get_the_date( _x( 'Y', 'yearly archives date format' ) ) );
+ } elseif ( is_month() ) {
+ /* translators: Monthly archive title. 1: Month name and year */
+ $title = sprintf( __( 'Month: %s' ), get_the_date( _x( 'F Y', 'monthly archives date format' ) ) );
+ } elseif ( is_day() ) {
+ /* translators: Daily archive title. 1: Date */
+ $title = sprintf( __( 'Day: %s' ), get_the_date( _x( 'F j, Y', 'daily archives date format' ) ) );
+ } elseif ( is_tax( 'post_format' ) ) {
+ if ( is_tax( 'post_format', 'post-format-aside' ) ) {
+ $title = _x( 'Asides', 'post format archive title' );
+ } elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) {
+ $title = _x( 'Galleries', 'post format archive title' );
+ } elseif ( is_tax( 'post_format', 'post-format-image' ) ) {
+ $title = _x( 'Images', 'post format archive title' );
+ } elseif ( is_tax( 'post_format', 'post-format-video' ) ) {
+ $title = _x( 'Videos', 'post format archive title' );
+ } elseif ( is_tax( 'post_format', 'post-format-quote' ) ) {
+ $title = _x( 'Quotes', 'post format archive title' );
+ } elseif ( is_tax( 'post_format', 'post-format-link' ) ) {
+ $title = _x( 'Links', 'post format archive title' );
+ } elseif ( is_tax( 'post_format', 'post-format-status' ) ) {
+ $title = _x( 'Statuses', 'post format archive title' );
+ } elseif ( is_tax( 'post_format', 'post-format-audio' ) ) {
+ $title = _x( 'Audio', 'post format archive title' );
+ } elseif ( is_tax( 'post_format', 'post-format-chat' ) ) {
+ $title = _x( 'Chats', 'post format archive title' );
+ }
+ } elseif ( is_post_type_archive() ) {
+ /* translators: Post type archive title. 1: Post type name */
+ $title = sprintf( __( 'Archives: %s' ), post_type_archive_title( '', false ) );
+ } elseif ( is_tax() ) {
+ $tax = get_taxonomy( get_queried_object()->taxonomy );
+ /* translators: Taxonomy term archive title. 1: Taxonomy singular name, 2: Current taxonomy term */
+ $title = sprintf( __( '%1$s: %2$s' ), $tax->labels->singular_name, single_term_title( '', false ) );
+ } else {
+ $title = __( 'Archives' );
+ }
+
+ /**
+ * Filters the archive title.
+ *
+ * @since 4.1.0
+ *
+ * @param string $title Archive title to be displayed.
+ */
+ return apply_filters( 'get_the_archive_title', $title );
+}
+
+/**
+ * Display category, tag, term, or author description.
+ *
+ * @since 4.1.0
+ *
+ * @see get_the_archive_description()
+ *
+ * @param string $before Optional. Content to prepend to the description. Default empty.
+ * @param string $after Optional. Content to append to the description. Default empty.
+ */
+function the_archive_description( $before = '', $after = '' ) {
+ $description = get_the_archive_description();
+ if ( $description ) {
+ echo $before . $description . $after;
+ }
+}
+
+/**
+ * Retrieve category, tag, term, or author description.
+ *
+ * @since 4.1.0
+ * @since 4.7.0 Added support for author archives.
+ *
+ * @see term_description()
+ *
+ * @return string Archive description.
+ */
+function get_the_archive_description() {
+ if ( is_author() ) {
+ $description = get_the_author_meta( 'description' );
+ } else {
+ $description = term_description();
+ }
+
+ /**
+ * Filters the archive description.
+ *
+ * @since 4.1.0
+ *
+ * @param string $description Archive description to be displayed.
+ */
+ return apply_filters( 'get_the_archive_description', $description );
+}
+
+/**
+ * Retrieve archive link content based on predefined or custom code.
+ *
+ * The format can be one of four styles. The 'link' for head element, 'option'
+ * for use in the select element, 'html' for use in list (either ol or ul HTML
+ * elements). Custom content is also supported using the before and after
+ * parameters.
+ *
+ * The 'link' format uses the `<link>` HTML element with the **archives**
+ * relationship. The before and after parameters are not used. The text
+ * parameter is used to describe the link.
+ *
+ * The 'option' format uses the option HTML element for use in select element.
+ * The value is the url parameter and the before and after parameters are used
+ * between the text description.
+ *
+ * The 'html' format, which is the default, uses the li HTML element for use in
+ * the list HTML elements. The before parameter is before the link and the after
+ * parameter is after the closing link.
+ *
+ * The custom format uses the before parameter before the link ('a' HTML
+ * element) and the after parameter after the closing link tag. If the above
+ * three values for the format are not used, then custom format is assumed.
+ *
+ * @since 1.0.0
+ *
+ * @param string $url URL to archive.
+ * @param string $text Archive text description.
+ * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom.
+ * @param string $before Optional. Content to prepend to the description. Default empty.
+ * @param string $after Optional. Content to append to the description. Default empty.
+ * @return string HTML link content for archive.
+ */
+function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
+ $text = wptexturize($text);
+ $url = esc_url($url);
+
+ if ('link' == $format)
+ $link_html = "\t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n";
+ elseif ('option' == $format)
+ $link_html = "\t<option value='$url'>$before $text $after</option>\n";
+ elseif ('html' == $format)
+ $link_html = "\t<li>$before<a href='$url'>$text</a>$after</li>\n";
+ else // custom
+ $link_html = "\t$before<a href='$url'>$text</a>$after\n";
+
+ /**
+ * Filters the archive link content.
+ *
+ * @since 2.6.0
+ * @since 4.5.0 Added the `$url`, `$text`, `$format`, `$before`, and `$after` parameters.
+ *
+ * @param string $link_html The archive HTML link content.
+ * @param string $url URL to archive.
+ * @param string $text Archive text description.
+ * @param string $format Link format. Can be 'link', 'option', 'html', or custom.
+ * @param string $before Content to prepend to the description.
+ * @param string $after Content to append to the description.
+ */
+ return apply_filters( 'get_archives_link', $link_html, $url, $text, $format, $before, $after );
+}
+
+/**
+ * Display archive links based on type and format.
+ *
+ * @since 1.2.0
+ * @since 4.4.0 $post_type arg was added.
+ *
+ * @see get_archives_link()
+ *
+ * @global wpdb $wpdb
+ * @global WP_Locale $wp_locale
+ *
+ * @param string|array $args {
+ * Default archive links arguments. Optional.
+ *
+ * @type string $type Type of archive to retrieve. Accepts 'daily', 'weekly', 'monthly',
+ * 'yearly', 'postbypost', or 'alpha'. Both 'postbypost' and 'alpha'
+ * display the same archive link list as well as post titles instead
+ * of displaying dates. The difference between the two is that 'alpha'
+ * will order by post title and 'postbypost' will order by post date.
+ * Default 'monthly'.
+ * @type string|int $limit Number of links to limit the query to. Default empty (no limit).
+ * @type string $format Format each link should take using the $before and $after args.
+ * Accepts 'link' (`<link>` tag), 'option' (`<option>` tag), 'html'
+ * (`<li>` tag), or a custom format, which generates a link anchor
+ * with $before preceding and $after succeeding. Default 'html'.
+ * @type string $before Markup to prepend to the beginning of each link. Default empty.
+ * @type string $after Markup to append to the end of each link. Default empty.
+ * @type bool $show_post_count Whether to display the post count alongside the link. Default false.
+ * @type bool|int $echo Whether to echo or return the links list. Default 1|true to echo.
+ * @type string $order Whether to use ascending or descending order. Accepts 'ASC', or 'DESC'.
+ * Default 'DESC'.
+ * @type string $post_type Post type. Default 'post'.
+ * }
+ * @return string|void String when retrieving.
+ */
+function wp_get_archives( $args = '' ) {
+ global $wpdb, $wp_locale;
+
+ $defaults = array(
+ 'type' => 'monthly', 'limit' => '',
+ 'format' => 'html', 'before' => '',
+ 'after' => '', 'show_post_count' => false,
+ 'echo' => 1, 'order' => 'DESC',
+ 'post_type' => 'post'
+ );
+
+ $r = wp_parse_args( $args, $defaults );
+
+ $post_type_object = get_post_type_object( $r['post_type'] );
+ if ( ! is_post_type_viewable( $post_type_object ) ) {
+ return;
+ }
+ $r['post_type'] = $post_type_object->name;
+
+ if ( '' == $r['type'] ) {
+ $r['type'] = 'monthly';
+ }
+
+ if ( ! empty( $r['limit'] ) ) {
+ $r['limit'] = absint( $r['limit'] );
+ $r['limit'] = ' LIMIT ' . $r['limit'];
+ }
+
+ $order = strtoupper( $r['order'] );
+ if ( $order !== 'ASC' ) {
+ $order = 'DESC';
+ }
+
+ // this is what will separate dates on weekly archive links
+ $archive_week_separator = '–';
+
+ $sql_where = $wpdb->prepare( "WHERE post_type = %s AND post_status = 'publish'", $r['post_type'] );
+
+ /**
+ * Filters the SQL WHERE clause for retrieving archives.
+ *
+ * @since 2.2.0
+ *
+ * @param string $sql_where Portion of SQL query containing the WHERE clause.
+ * @param array $r An array of default arguments.
+ */
+ $where = apply_filters( 'getarchives_where', $sql_where, $r );
+
+ /**
+ * Filters the SQL JOIN clause for retrieving archives.
+ *
+ * @since 2.2.0
+ *
+ * @param string $sql_join Portion of SQL query containing JOIN clause.
+ * @param array $r An array of default arguments.
+ */
+ $join = apply_filters( 'getarchives_join', '', $r );
+
+ $output = '';
+
+ $last_changed = wp_cache_get_last_changed( 'posts' );
+
+ $limit = $r['limit'];
+
+ if ( 'monthly' == $r['type'] ) {
+ $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date $order $limit";
+ $key = md5( $query );
+ $key = "wp_get_archives:$key:$last_changed";
+ if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
+ $results = $wpdb->get_results( $query );
+ wp_cache_set( $key, $results, 'posts' );
+ }
+ if ( $results ) {
+ $after = $r['after'];
+ foreach ( (array) $results as $result ) {
+ $url = get_month_link( $result->year, $result->month );
+ if ( 'post' !== $r['post_type'] ) {
+ $url = add_query_arg( 'post_type', $r['post_type'], $url );
+ }
+ /* translators: 1: month name, 2: 4-digit year */
+ $text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $result->month ), $result->year );
+ if ( $r['show_post_count'] ) {
+ $r['after'] = ' (' . $result->posts . ')' . $after;
+ }
+ $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );