Ticket #7463: 7463.2.diff

File 7463.2.diff, 3.4 KB (added by ionfish, 4 years ago)
Line 
1Index: wp-includes/formatting.php
2===================================================================
3--- wp-includes/formatting.php  (revision 10191)
4+++ wp-includes/formatting.php  (working copy)
5@@ -2158,4 +2158,33 @@
6        return $str;
7 }
8 
9+/**
10+ * Implodes an array and adds a final conjuction.
11+ *
12+ * Given the array <code>array('John', 'Paul', 'George', 'Ringo')</code> it will
13+ * return the string <code>'John, Paul, George and Ringo'</code>.
14+ *
15+ * @package WordPress
16+ * @since 2.8
17+ *
18+ * @internal
19+ * @param array $array
20+ * @param string $glue
21+ * @param string $conjuction
22+ * @return string
23+ */
24+function _implode_nicely( $array, $glue = ', ', $conjuction = 'and' ) {
25+       if ( !is_array($array) || count($array) == 0 )
26+               return;
27+       
28+       $last_value = array_pop($array);
29+       
30+       if ( count($array) > 0 )
31+               $output = implode($glue, $array) . " $conjuction $last_value";
32+       else
33+               $output = $last_value;
34+       
35+       return $output;
36+}
37+
38 ?>
39Index: wp-includes/general-template.php
40===================================================================
41--- wp-includes/general-template.php    (revision 10191)
42+++ wp-includes/general-template.php    (working copy)
43@@ -581,6 +581,56 @@
44 }
45 
46 /**
47+ * Outputs tag titles for tag intersections and unions.
48+ *
49+ * @package WordPress
50+ * @since 2.8
51+ *
52+ * @global $wpdb object
53+ * @param $tag_wrapper string
54+ * @return string
55+ */
56+function multiple_tag_titles($format = '&#8216;%s&#8217;') {
57+       global $wpdb;
58+
59+       if ( !is_tag() )
60+               return;
61+       
62+       if ( $tag_slugs = get_query_var('tag_slug__and') )
63+               $connective = __('and');
64+       elseif ( $tag_slugs = get_query_var('tag_slug__in') )
65+               $connective = __('or');
66+       else
67+               $single_tag = intval( get_query_var('tag_id') );
68+       
69+       $tags = array();
70+       if ( $tag_slugs ) {
71+               foreach ( $tag_slugs as $tag_slug ) {
72+                       $tag = get_term_by('slug', $tag_slug, 'post_tag', OBJECT, 'display');
73+                       if ( !is_wp_error($tag) && !empty($tag->name) )
74+                               $tags[] = $tag->name;
75+               }
76+       } elseif ( $single_tag ) {
77+               $tag = &get_term($single_tag, 'post_tag', OBJECT, 'display');
78+               if ( is_wp_error($tag) || empty($tag->name) )
79+                       return false;
80+               else
81+                       $tags[] = $tag->name;
82+       } else {
83+               return;
84+       }
85+
86+       if ( strlen($format) > 0 ) {
87+               foreach ( $tags as $index => $tag )
88+                       $tags[$index] = sprintf($format, $tag);
89+       }
90+               
91+       $tags = _implode_nicely($tags, __(', '), $connective);
92+       $tags = apply_filters('multiple_tag_titles', $tags);
93+       return $tags;
94+}
95+
96+/**
97  * Display or retrieve page title for post archive based on date.
98  *
99  * Useful for when the template only needs to display the month and year, if
100Index: wp-content/themes/default/archive.php
101===================================================================
102--- wp-content/themes/default/archive.php       (revision 10191)
103+++ wp-content/themes/default/archive.php       (working copy)
104@@ -15,7 +15,7 @@
105          <?php /* If this is a category archive */ if (is_category()) { ?>
106                <h2 class="pagetitle">Archive for the &#8216;<?php single_cat_title(); ?>&#8217; Category</h2>
107          <?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
108-               <h2 class="pagetitle">Posts Tagged &#8216;<?php single_tag_title(); ?>&#8217;</h2>
109+               <h2 class="pagetitle">Posts Tagged <?php echo multiple_tag_titles(); ?></h2>
110          <?php /* If this is a daily archive */ } elseif (is_day()) { ?>
111                <h2 class="pagetitle">Archive for <?php the_time('F jS, Y'); ?></h2>
112          <?php /* If this is a monthly archive */ } elseif (is_month()) { ?>