css Polylang的自定义语言切换器。包含PHP函数和SCSS样式。 HTML标记使用BEM方法。 SCSS文件是你

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了css Polylang的自定义语言切换器。包含PHP函数和SCSS样式。 HTML标记使用BEM方法。 SCSS文件是你相关的知识,希望对你有一定的参考价值。

/* Component: Languages */
.languages {
  
  // El: Item
  &__item {
    text-transform: uppercase;
    color: #899099;
    font-size: 13px;
    line-height: 1.15;
    
    // Mod: Current
    &--current {
      color: #212121;
    }

    // Divider
    &:before {
      content: ' / ';
      color: #899099;
    }

    // Remove divider from first item
    &:first-child:before {
      content: '';
    }
  }

  // Hover Styling for links
  a.languages__item:hover {
    color: #212121;
  }
}
<?php // Don't copy this line in functions.php file if it's already added.

/**
 * Show Polylang Languages with Custom Markup
 * @param  string $class Add custom class to the languages container
 * @return string        
 */
function rarus_polylang_languages( $class = '' ) {

  if ( ! function_exists( 'pll_the_languages' ) ) return;

  // Gets the pll_the_languages() raw code
  $languages = pll_the_languages( array(
    'display_names_as'       => 'slug',
    'hide_if_no_translation' => 1,
    'raw'                    => true
  ) ); 

  $output = '';

  // Checks if the $languages is not empty
  if ( ! empty( $languages ) ) {

    // Creates the $output variable with languages container
    $output = '<div class="languages' . ( $class ? ' ' . $class : '' ) . '">';

    // Runs the loop through all languages
    foreach ( $languages as $language ) {

      // Variables containing language data
      $id             = $language['id'];
      $slug           = $language['slug'];
      $url            = $language['url'];
      $current        = $language['current_lang'] ? ' languages__item--current' : '';
      $no_translation = $language['no_translation'];

      // Checks if the page has translation in this language
      if ( ! $no_translation ) {
        // Check if it's current language
        if ( $current ) {
          // Output the language in a <span> tag so it's not clickable
          $output .= "<span class=\"languages__item$current\">$slug</span>";
        } else {
          // Output the language in an anchor tag
          $output .= "<a href=\"$url\" class=\"languages__item$current\">$slug</a>";
        }
      }

    }

    $output .= '</div>';

  }

  return $output;
}
/* Component: Languages */
.languages__item {
  text-transform: uppercase;
  color: #899099;
  font-size: 13px;
  font-size:  1.3rem;
  line-height: 1.15;
}
.languages__item--current {
  color: #212121;
}
.languages__item:before {
  content: ' / ';
  color: #899099;
}
.languages__item:first-child:before {
  content: '';
}
.languages a.languages__item:hover {
  color: #212121;
}

以上是关于css Polylang的自定义语言切换器。包含PHP函数和SCSS样式。 HTML标记使用BEM方法。 SCSS文件是你的主要内容,如果未能解决你的问题,请参考以下文章

如何仅为我的自定义 vue 组件包含外部 css 文件?

如何防止scaffold.css 覆盖我的自定义css?

tailwindcss/vue:生成的 css 文件不包含 <style> 部分的自定义类

Express Checkout Paypal Payment Gateway For Woocommerce 存在 Polylang 问题

有没有办法制作包含其他标签的自定义 HTML 标签?

Grails 插件中的自定义 CSS 和 JS