WordPress.org

Make WordPress Core

Ticket #14161: 14161.patch

File 14161.patch, 3.0 KB (added by ramiy, 8 years ago)

single_term_title() function

  • general-template.php

     
    517517        global $wpdb, $wp_locale, $wp_query;
    518518
    519519        $cat = get_query_var('cat');
     520        $category_name = get_query_var('category_name');
    520521        $tag = get_query_var('tag_id');
    521         $category_name = get_query_var('category_name');
     522        $taxonomy = get_query_var('taxonomy');
    522523        $author = get_query_var('author');
    523524        $author_name = get_query_var('author_name');
    524525        $m = get_query_var('m');
     
    548549                        $title = apply_filters('single_cat_title', $cat->name);
    549550        }
    550551
     552        // If there's a tag
    551553        if ( !empty($tag) ) {
    552554                $tag = get_term($tag, 'post_tag', OBJECT, 'display');
    553555                if ( is_wp_error( $tag ) )
     
    574576                $title = $my_year . ($my_month ? $t_sep . $my_month : "") . ($my_day ? $t_sep . $my_day : "");
    575577        }
    576578
     579        // If there's a year
    577580        if ( !empty($year) ) {
    578581                $title = $year;
    579582                if ( !empty($monthnum) )
     
    590593
    591594        // If there's a taxonomy
    592595        if ( is_tax() ) {
    593                 $taxonomy = get_query_var( 'taxonomy' );
    594596                $tax = get_taxonomy( $taxonomy );
    595597                $term = $wp_query->get_queried_object();
    596598                $term = $term->name;
     
    603605                $title = sprintf(__('Search Results %1$s %2$s'), $t_sep, strip_tags($search));
    604606        }
    605607
     608        //If it's a 404 page
    606609        if ( is_404() ) {
    607610                $title = __('Page not found');
    608611        }
     
    722725 */
    723726function single_tag_title($prefix = '', $display = true ) {
    724727        global $wp_query;
     728
    725729        if ( !is_tag() )
    726730                return;
    727731
    728732        $tag = $wp_query->get_queried_object();
    729733
    730         if ( ! $tag )
     734        if ( !$tag )
    731735                return;
    732736
    733737        $my_tag_name = apply_filters('single_tag_title', $tag->name);
     
    740744}
    741745
    742746/**
     747 * Display or retrieve page title for taxonomy term archive.
     748 *
     749 * Useful for taxonomy term template files for displaying the taxonomy term page title.
     750 * It has less overhead than {@link wp_title()}, because of its limited implementation.
     751 *
     752 * It does not support placing the separator after the title, but by leaving the
     753 * prefix parameter empty, you can set the title separator manually. The prefix
     754 * does not automatically place a space between the prefix, so if there should
     755 * be a space, the parameter value will need to have it at the end.
     756 *
     757 * @since 3.0.1
     758 *
     759 * @param string $prefix Optional. What to display before the title.
     760 * @param bool $display Optional, default is true. Whether to display or retrieve title.
     761 * @return string|null Title when retrieving, null when displaying or failure.
     762 */
     763function single_term_title($prefix = '', $display = true ) {
     764        global $wp_query;
     765
     766        if ( !is_term() )
     767                return;
     768
     769        $term = $wp_query->get_queried_object();
     770
     771        if ( !$term )
     772                return;
     773
     774        $my_term_name = apply_filters('single_term_title', $term->name);
     775        if ( !empty($my_term_name) ) {
     776                if ( $display )
     777                        echo $prefix . $my_term_name;
     778                else
     779                        return $my_term_name;
     780        }
     781}
     782
     783/**
    743784 * Display or retrieve page title for post archive based on date.
    744785 *
    745786 * Useful for when the template only needs to display the month and year, if