Shortcode for flags only as "bogo-flags"
-
Hi Takayuki,
Hope to see this patch in next release?
Best regards,
diff -r -u bogo-orig/bogo.php bogo/bogo.php --- bogo-orig/bogo.php 2015-12-01 11:25:56.000000000 +0100 +++ bogo/bogo.php 2015-12-16 14:47:34.000000000 +0100 @@ -111,6 +111,7 @@ } add_shortcode( 'bogo', 'bogo_language_switcher' ); +add_shortcode( 'bogo-flags', 'bogo_language_switcher_flags' ); add_action( 'wp_enqueue_scripts', 'bogo_enqueue_scripts' ); diff -r -u bogo-orig/includes/link-template.php bogo/includes/link-template.php --- bogo-orig/includes/link-template.php 2015-11-29 21:47:32.000000000 +0100 +++ bogo/includes/link-template.php 2015-12-16 15:19:45.000000000 +0100 @@ -247,6 +247,66 @@ } } +function bogo_language_switcher_flags( $args = '' ) { + $args = wp_parse_args( $args, array( + 'echo' => false ) ); + + $links = bogo_language_switcher_links( $args ); + $total = count( $links ); + $count = 0; + + $output = ''; + + foreach ( $links as $link ) { + $count += 1; + $class = array(); + $class[] = bogo_language_tag( $link['locale'] ); + $class[] = bogo_lang_slug( $link['locale'] ); + + if ( get_locale() == $link['locale'] ) { + $class[] = 'current'; + } + + if ( 1 == $count ) { + $class[] = 'first'; + } + + if ( $total == $count ) { + $class[] = 'last'; + } + + $class = implode( ' ', array_unique( $class ) ); + + $label = $link['native_name'] ? $link['native_name'] : $link['title']; + $title = $link['title']; + + if ( empty( $link['href'] ) ) { + $li = sprintf( + '<li class="%1$s"></li>', + $class); + } else { + $li = sprintf( + '<a rel="alternate" hreflang="%1$s" href="%2$s" title="%3$s"><li class="%4$s"></li></a>', + $link['lang'], + esc_url( $link['href'] ), + esc_attr( $title ), + $class); + } + + $output .= $li . "\n"; + } + + $output = '<ul class="bogo-language-switcher">' . $output . '</ul>' . "\n"; + + $output = apply_filters( 'bogo_language_switcher', $output, $args ); + + if ( $args['echo'] ) { + echo $output; + } else { + return $output; + } +} + function bogo_language_switcher_links( $args = '' ) { global $wp_query;
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Shortcode for flags only as "bogo-flags"’ is closed to new replies.