【问题标题】:wordpress qtranslate flags dropdownwordpress qtranslate 标志下拉菜单
【发布时间】:2012-01-11 09:40:17
【问题描述】:

我正在使用“qtranslate”插件进行文字按,以便在我的网站中使用元语言,

如何创建一个只显示其中标志的组合?

我尝试使用以下代码生成下拉列表,但它只在列表中显示标志:

echo qtrans_generateLanguageSelectCode('image');
$header_shortcodes = html_entity_decode(get_option(PREFIX.'_header_shortcodes'), ENT_QUOTES, 'UTF-8');
echo $header_shortcodes = apply_filters('themefuse_shortcodes',$header_shortcodes);

谢谢

【问题讨论】:

  • 你找到解决方案了吗?
  • 好吧,我最终不得不自己解决它,我在这里接受了其中一个建议并自己编写了它。我编辑了插件并使用 msDropdown 插件来创建图像列表。我将在几秒钟内发布代码
  • 谢谢你!我建议您将自己的答案设置为这个答案,以便其他人可以找到一些帮助:)!

标签: php jquery wordpress qtranslate


【解决方案1】:

我最终在这里采用了其中一种解决方案,并将其与msdropdown 插件相结合

第 1 步:转到插件文件夹并打开 qtranslate/qtranslate_widget.php。有在行号。 112 你会发现 case:'both';现在该案例在第 123 行结束的地方添加以下代码(另写一个案例)

case 'bothkria': ?>
     <div id="language_chooser">
        <select name="langchooser" id="langchooser" onchange="$(window.location).attr('href',this.value);">
        <?php 
            /************************
            * go over the enabled languages and create all the languages options
            * the first marked "selected" is reffered to the current chosen language
            * the value is the relevant url and the title is the url of the image.
            * 
            * After creating the selectbox we will run the msdropdown plugin to make it a designed select box
            * Of corse dont forget to have a reference to the msdropdown js library
            * <script type="text/javascript" src="js/jquery.dd.js"></script>
            * you can find it here http://www.marghoobsuleman.com/jquery-image-dropdown
            *************************/
            foreach(qtrans_getSortedLanguages() as $language)
            {
                if($q_config['language']==$language) {?>
                    <option selected="selected" value="<?php echo qtrans_convertURL($url, $language);?>" title="<?php echo get_option('home');?>/wp-content/<?php echo $q_config['flag_location'];?><?php echo $q_config['flag'][$language] ?>"><?php print strtoupper($q_config['pre_domain'][$language]); ?></option>
          <?php } else {  ?>
                    <option value="<?php print qtrans_convertURL($url, $language);?>" title="<?php echo get_option('home');?>/wp-content/<?php echo $q_config['flag_location'];?><?php echo $q_config['flag'][$language] ?>"><?php print strtoupper($q_config['pre_domain'][$language]); ?></option>
          <?php }
            } ?>
        </select> 
        <div id="selectbox_script" style="display:none;">
                 <script type="text/javascript">
                 /* <![CDATA[ */
                    $(document).ready(function(e) {
                        try {
                        $("#langchooser").msDropDown();
                        } catch(e) {
                        alert(e.message);
                        }
                    });
                 /* ]]> */
                 </script>
        </div>
     </div>
    <?php break; ?> 

【讨论】:

  • 你能告诉我如何在这里使用 msdropdown 吗?
  • 嗯,你在上面的回复中有确切的细节......这是很久以前的事了,从那以后我不再使用这个插件了 - 我已经切换到我认为更好的 WPML 并且全面。
【解决方案2】:

我从您的问题中了解到,您需要一个包含标志图像和语言的下拉列表,如果需要,请使用以下代码。

我在 qtranslate 版本 2.5.28 上编写和测试了这段代码,尽管它也适用于其他版本,参考行号根据这个版本给出。

第 1 步:转到插件文件夹并打开 qtranslate/qtranslate_widget.php。有在行号。 112你会发现case:'both'; 现在该案例在第 123 行结束 在其下方添加以下代码(另写一个案例) `

case 'bothkria':
            if($_REQUEST['lang']!=""){ $kria = $_REQUEST['lang'];}else{$kria = $q_config['default_language'];}
            echo '<span class="s_selected"><img src="'.get_option('home').'/wp-content/'.$q_config['flag_location'].''.$q_config['flag'][$kria].'" alt="'.$q_config['flag'][$kria].'" /> '.$q_config['language_name'][$kria].'</span>
                    <ul class="s_options">';
            foreach(qtrans_getSortedLanguages() as $language){
                      echo '<li><a href="'.qtrans_convertURL($url, $language).'"><img src="'.get_option('home').'/wp-content/'.$q_config['flag_location'].''.$q_config['flag'][$language].'" alt="'.$q_config['language_name'][$language].'" />'.$q_config['language_name'][$language].'</a></li>';
            }
                    echo '</ul>';
            break;

第 2 步:您想要显示它的位置只需粘贴以下代码 &lt;div id="language_switcher" class="s_switcher"&gt;&lt;?php echo qtrans_generateLanguageSelectCode('bothkria'); ?&gt;&lt;/div&gt;

第 3 步:相应设计的 CSS 类,此处提供帮助,您可以根据自己的主题进行更改。 `

.s_switcher {
              z-index: 10;
              position: absolute;
              top:6px;
              right:255px;
              font-size: 11px;
              background: #f6f6f6 url(../images/dropdown.gif) no-repeat 100% 6px;
              border-top: 1px solid #e9e9e9;
              border-left: 1px solid #e9e9e9;
              border-right: 1px solid #f6f6f6;
              border-bottom: 1px solid #f6f6f6;
              border-radius: 3px;
              -moz-border-radius: 3px;
              -webkit-border-radius: 3px;
            }
            .s_switcher ul {
              margin-bottom: 0;
            }
            .s_switcher span.s_selected,
            .s_switcher li,
            .s_switcher li a
            {
              display: block;
              height: 22px;
              line-height: 20px;
              text-indent: 7px;
            }
            .s_switcher span.s_selected {
              cursor: default;
              color: #999;
            }
            .s_switcher .s_options {
              cursor: pointer;
              display: none;
            }
            .s_switcher img {
              display: inline;
              margin: -1px 3px 0 0;
              vertical-align: middle;
              margin-left:10px;
            }

            #language_switcher .s_selected, #language_switcher .s_options li a {
                font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
                text-decoration:none;
                font-size:12px;
                color:#333;
                }

            #language_switcher .s_options li a{
                color:#999;}
            #language_switcher .s_options li a:hover{
                color:#333;}

` 完成上传文件并检查。 希望这是你想要的。 享受

谢谢!

【讨论】:

  • 谢谢我试过了,但它没有显示为下拉菜单,它只是生成了一个
      ,我怎样才能让它显示为一个下拉菜单?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-10-15
  • 2012-05-17
  • 1970-01-01
  • 2017-02-17
  • 2016-06-23
  • 2011-07-20
  • 2014-07-17
相关资源
最近更新 更多