简体   繁体   English

如何在标题中放置语言切换器?

[英]How to place language switcher in header?

So, I'm working on my website, in Wordpress. 因此,我正在使用Wordpress在我的网站上工作。 To say on the beggining, I'm no php coder, I just stambled on this thing working on my wordpress website. 首先,我不是php编码器,我只是在wordpress网站上研究了这个东西。 I bought a theme and installed Simple Language Switcher plugin. 我购买了一个主题并安装了Simple Language Switcher插件。 It works but I don't know how to place it where I want. 它可以工作,但我不知道如何将其放置在我想要的位置。 I tried it everywhere in my header.php file but no luck. 我在header.php文件的任何地方都尝试过,但是没有运气。 You can see in the image below where it is right now and where I want it (right, where I wrote HERE). 您可以在下面的图像中看到它的当前位置和所需位置(对,我在此处写的位置)。 And the link for the plugin: 以及插件的链接:

http://www.mendoweb.be/blog/wordpress-plugin-simple-language-switcher/ http://www.mendoweb.be/blog/wordpress-plugin-simple-language-switcher/

在此处输入图片说明

This is the code for my language bar: 这是我的语言栏的代码:

<?php if( function_exists( 'simple_language_switcher' ) ) { ?>
<div id="simple-language-switcher"><?php simple_language_switcher(); ?></div>
<?php } ?>

Here's my header.php file right now: 现在是我的header.php文件:

<?php
/**
 * The Header for our theme.
 *
 * Displays all of the <head> section and everything up till <main id="main">
 *
 * @package Terrifico
 */
?><!DOCTYPE html>
<!--[if IE 7]>
<html class="ie ie7" <?php language_attributes(); ?>>
<![endif]-->
<!--[if IE 8]>
<html class="ie ie8" <?php language_attributes(); ?>>
<![endif]-->
<!--[if !(IE 7) | !(IE 8)  ]><!-->
<html <?php language_attributes(); ?>>
<!--<![endif]-->
<head>
<?php global $data; ?>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
<title><?php wp_title( '|', true, 'right' ); ?></title>
<link rel="profile" href="" />
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
<?php if ($data['enable_favicon'] == 1 ) { ?>
    <link rel="shortcut icon" href="<?php echo $data['favicon']; ?>" type="image/x-icon" />

<?php } ?>
<?php // Loads HTML5 JavaScript file to add support for HTML5 elements in older IE versions. ?>
<!--[if lt IE 9]>
<script src="<?php echo get_template_directory_uri(); ?>/js/html5.js" type="text/javascript"></script>
<![endif]-->

<?php terrifico_custom_styling(); ?>
<?php wp_head(); ?>
<?php if ($data['custom_css'] <> "") { ?>
    <style type="text/css">
        <?php echo $data['custom_css']; ?>
    </style>
<?php } ?>  
</head> 

<body <?php body_class(); ?>>

<div id="grid-container">
    <?php if ( $data['top_panel_enable'] == 1 ) { get_template_part( 'top-panel' ); }; ?>


<?php if( function_exists( 'simple_language_switcher' ) ) { ?>
<div id="simple-language-switcher"><?php simple_language_switcher(); ?></div>
<?php } ?>

    <div class="clear"></div>

    <div id="branding" class="<?php echo $data['layout']; ?>">
        <header id="header">
            <div id="logo">

                <?php if ( $data['text_logo_enable'] != 1 ) { ?>
                    <a href="<?php echo home_url(); ?>/"><img src="<?php echo $data['logo']; ?>" alt="<?php echo $data['logo_alt_text']; ?>"/></a>
                <?php } else { ?>
                    <a href="<?php echo home_url(); ?>/"><?php echo $data['logo_alt_text']; ?></a>
                <?php } ?>
            </div>      
            <?php if ( $data['menu_separated'] != 1 ) { ?>
                <div id="nav-holder">
                    <nav id="site-navigation-in" class="main-navigation" role="navigation">
                        <?php wp_nav_menu(array('theme_location' => 'main_navigation', 'container' => false,'menu_id'=>'menu-main-navigation','menu_class' => 'sf-menu sf-js-enabled sf-shadow', 'fallback_cb'=> 'terrifico_selectmenu', )); ?>
                    </nav><!--site-navigation-->
                </div>
            <?php } ?>
            <script type="text/javascript">
                var sf=jQuery.noConflict();
                sf(window).load(function(){
                // superFish
                sf('ul.sf-menu').supersubs({
                minWidth:    16, // minimum width of sub-menus in em units
                maxWidth:    40, // maximum width of sub-menus in em units
                extraWidth:  1 // extra width can ensure lines don't sometimes turn over
                })
                .superfish(); // call supersubs first, then superfish
                });
            </script>
    </div><!--branding-->
<?php if ( $data['menu_separated'] == 1 ) { ?>
    <div id="nav-holder" class="<?php echo $data['layout']; ?>">
        <nav id="site-navigation" class="main-navigation" role="navigation">
            <?php wp_nav_menu(array('theme_location' => 'main_navigation', 'container' => false,'menu_id'=>'menu-main-navigation','menu_class' => 'sf-menu sf-js-enabled sf-shadow', 'fallback_cb'=> 'terrifico_selectmenu', )); ?>
        </nav><!--site-navigation-->
    </div>
<?php } ?>
    <?php if ( $data['front_page_blog_index'] == 1 ) {?>
        <?php if (! is_home()) { ?>
            <?php if ( $data['page_header_on'] == 1 ) { ?>
                <?php get_template_part( 'page-header' ); ?>
            <?php } ?>
        <?php } ?>
    <?php } else { ?>
        <?php if ( $data['page_header_on'] == 1 ) { ?>
            <?php get_template_part( 'page-header' ); ?>
        <?php } ?>
    <?php } ?>

The file you need to edit is top-panel.php, in the same directory as header.php. 您需要编辑的文件是top-panel.php,与header.php在同一目录中。 It contains the expanded PHP code for that part of the header in your theme. 它包含主题中标题部分的扩展PHP代码。 You can see where it's referenced in header.php here, just above where you currently have the language bar code: 您可以在此处当前具有语言条形码的位置上方的header.php中看到它的引用位置:

<?php if ( $data['top_panel_enable'] == 1 ) { get_template_part( 'top-panel' ); }; ?>

It's increasingly common for WordPress themes, when their designers want to keep everything tidy, to have usual theme parts like header.php, footer.php, etc. divided even further into sub-files. 当他们的设计师希望保持所有内容整洁时,将通常的主题部分(如header.php,footer.php等)进一步划分为子文件时,对于WordPress主题而言,这已越来越普遍。 In other words, top-panel.php is to header.php, like header.php is to index.php. 换句话说,top-panel.php是header.php,就像header.php是index.php。

First, back up any files you edit, then carefully insert the language bar code in top-panel.php so the file looks something like this: 首先, 备份您编辑的所有文件,然后小心地将语言条形码插入top-panel.php中,以便文件看起来像这样:

<?php
/**
 * @package Terrifico
 */
global $data; ?>
    <div id="top-panel" class="<?php echo $data['layout']; ?>">
        <div id="info-box">
            <?php if ( $data['top_contact_enable'] == 1 ) { get_template_part( 'contact-bar' ); }; ?>
            <?php if(class_exists('Woocommerce')) { ?>
                <?php if ( $data['header_social_enable'] == 1 && $data['shopping_cart_enable'] == 0 ) { get_template_part( 'social-bar' ); }; ?>

                <?php if ( $data['shopping_cart_enable'] == 1 ) { get_template_part( 'shopping-cart' ); } ;?>
            <?php } else { ?>
                <?php if ( $data['header_social_enable'] == 1 ) { get_template_part( 'social-bar' ); }; ?>
            <?php } ?>

    /* INSERT LANGUAGE BAR CODE */
    <?php if( function_exists( 'simple_language_switcher' ) ) { ?>
    <div id="simple-language-switcher"><?php simple_language_switcher(); ?></div>
    <?php } ?>
    /* END LANGUAGE BAR CODE */

        </div><!-- #info-box -->
    </div><!-- #top-panel -->

Basically, you want the language bar code to be inside the top-panel <div> . 基本上,你想要的语言条码是顶部面板里面 <div> That's the div that contains the other divs for "Have any questions?", social icons, etc. 该div包含“是否有任何问题?”,社交图标等其他div。

I don't actually have the theme installed to experiment with right now, but you'll probably have to play a little with the CSS or the code above to get it positioned perfectly. 我目前尚未实际安装该主题以进行试验,但是您可能需要稍微使用CSS或上面的代码才能使其完美定位。 Hope I explained it clearly enough and that this helps. 希望我能解释得足够清楚,这对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM