PluginProbe
Bogo / 2.4
Bogo v2.4
3.9.3 trunk 1.0 1.1 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5 2.6 2.6.1 2.7 2.8 2.8.1 2.9 3.0 3.0.1 All 52 releases
← All changes | includes/link-template.php +82 -6 2.72.4 View file →
@@ -161,15 +161,16 @@
161 161 'href' => get_permalink( $translation ) );
162 162 }
163 163 }
164 164 } else {
165 - $available_locales = bogo_available_locales( array(
166 - 'exclude_enus_if_inactive' => true ) );
165 + $available_locales = bogo_available_locales();
167 166
168 - foreach ( $available_locales as $locale ) {
169 - $languages[] = array(
170 - 'hreflang' => bogo_language_tag( $locale ),
171 - 'href' => bogo_url( null, $locale ) );
167 + if ( 1 < count( $available_locales ) ) {
168 + foreach ( $available_locales as $locale ) {
169 + $languages[] = array(
170 + 'hreflang' => bogo_language_tag( $locale ),
171 + 'href' => bogo_url( null, $locale ) );
172 + }
172 173 }
173 174 }
174 175
175 176 $languages = apply_filters( 'bogo_rel_alternate_hreflang', $languages );
@@ -186,8 +187,81 @@
186 187 }
187 188 }
188 189 }
189 190
191 +function bogo_language_switcher( $args = '' ) {
192 + global $wp_query;
193 +
194 + $defaults = array(
195 + 'echo' => false );
196 +
197 + $args = wp_parse_args( $args, $defaults );
198 +
199 + $locale = get_locale();
200 + $available_languages = bogo_available_languages();
201 +
202 + $translations = array();
203 + $is_singular = false;
204 + $post_id = get_queried_object_id();
205 +
206 + if ( is_singular() || ! empty( $wp_query->is_posts_page ) ) {
207 + $translations = bogo_get_post_translations( $post_id );
208 + $is_singular = true;
209 + }
210 +
211 + $output = '<ul class="bogo-language-switcher">';
212 +
213 + $total = count( $available_languages );
214 + $count = 0;
215 +
216 + foreach ( $available_languages as $code => $name ) {
217 + $count += 1;
218 + $class = array();
219 + $class[] = bogo_language_tag( $code );
220 + $class[] = bogo_lang_slug( $code );
221 +
222 + if ( $locale == $code ) {
223 + $class[] = 'current';
224 + }
225 +
226 + if ( 1 == $count ) {
227 + $class[] = 'first';
228 + }
229 +
230 + if ( $total == $count ) {
231 + $class[] = 'last';
232 + }
233 +
234 + $class = implode( ' ', array_unique( $class ) );
235 +
236 + $output .= '<li class="' . esc_attr( $class ) . '">';
237 +
238 + if ( $is_singular ) {
239 + if ( empty( $translations[$code] ) || $locale == $code ) {
240 + $output .= esc_html( $name );
241 + } else {
242 + $output .= '<a rel="alternate" hreflang="' . bogo_language_tag( $code ) . '" href="' . get_permalink( $translations[$code] ) . '">' . esc_html( $name ) . '</a>';
243 + }
244 + } else {
245 + if ( $locale == $code ) {
246 + $output .= esc_html( $name );
247 + } else {
248 + $output .= '<a rel="alternate" hreflang="' . bogo_language_tag( $code ) . '" href="' . esc_url( bogo_url( null, $code ) ) . '">' . esc_html( $name ) . '</a>';
249 + }
250 + }
251 +
252 + $output .= '</li>';
253 + }
254 +
255 + $output .= '</ul>' . "\n";
256 +
257 + if ( $args['echo'] ) {
258 + echo $output;
259 + } else {
260 + return $output;
261 + }
262 +}
263 +
190 264 add_filter( 'get_previous_post_join', 'bogo_adjacent_post_join', 10, 3 );
191 265 add_filter( 'get_next_post_join', 'bogo_adjacent_post_join', 10, 3 );
192 266
193 267 function bogo_adjacent_post_join( $join, $in_same_term, $excluded_terms ) {
@@ -224,4 +298,6 @@
224 298 }
225 299
226 300 return $where;
227 301 }
302 +
303 +?>