Twitter Bootstrap布局在Wordpress模板中完全破解

时间:2015-08-05 07:26:42

标签: wordpress twitter-bootstrap

我将Twitter Bootstrap嵌入到Wordpress模板中,但它已被破坏。我不确定为什么,因为HTML看起来应该是这样。这是嵌入Twitter Bootstrap后的结果:

enter image description here

以下是header.php文件的内容:

<?php
/**
 * The template for displaying the header
 *
 * Displays all of the head element and everything up until the "site-content" div.
 *
 * @package WordPress
 * @subpackage Twenty_Fifteen
 * @since Twenty Fifteen 1.0
 */
?><!DOCTYPE html>
<html <?php language_attributes(); ?> class="no-js">
<head>
    <meta charset="<?php bloginfo( 'charset' ); ?>">
    <meta name="viewport" content="width=device-width">
    <link rel="profile" href="http://gmpg.org/xfn/11">
    <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <!--[if lt IE 9]>
    <script src="<?php echo esc_url( get_template_directory_uri() ); ?>/js/html5.js"></script>
    <![endif]-->
    <?php wp_head(); ?>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>

<body <?php body_class(); ?>>
<div id="page" class="hfeed site container">
    <!-- <a class="skip-link screen-reader-text" href="#content"><?php _e( 'Skip to content', 'twentyfifteen' ); ?></a> -->
    <div class="row">

        <div id="sidebar" class="sidebar col-xs-12 co-md-4">
            <header id="masthead" class="site-header" role="banner">
                <div class="site-branding">
                    <?php
                        if ( is_front_page() && is_home() ) : ?>
                            <h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
                        <?php else : ?>
                            <p class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></p>
                        <?php endif;

                        $description = get_bloginfo( 'description', 'display' );
                        if ( $description || is_customize_preview() ) : ?>
                            <p class="site-description"><?php echo $description; ?></p>
                        <?php endif;
                    ?>
                    <button class="secondary-toggle"><?php _e( 'Menu and widgets', 'twentyfifteen' ); ?></button>
                </div><!-- .site-branding -->
            </header><!-- .site-header -->

            <?php get_sidebar(); ?>
        </div><!-- .sidebar -->

        <div id="content" class="site-content col-xs-12 co-md-8">

2 个答案:

答案 0 :(得分:1)

您在列div

上错过了类别

co-md-4应为col-md-4co-md-8应为col-md-8

很难说这是否是您的模板被破坏的原因,但它至少是一个开始。

答案 1 :(得分:0)

经过几个小时的挖掘Wordpress,我终于得到了答案。它实际上相当棘手,因为这不是嵌入Twitter Bootstrap的错误。 在footer.php中,它具有此功能wp_footer,它会将skip-link-focus-fix.js添加到HTML页面。

然后这个javascript文件导致布局破坏:

/**
 * Makes "skip to content" link work correctly in IE9, Chrome, and Opera
 * for better accessibility.
 *
 * @link http://www.nczonline.net/blog/2013/01/15/fixing-skip-to-content-links/
 */

( function() {
    var ua = navigator.userAgent.toLowerCase();

    if ( ( ua.indexOf( 'webkit' ) > -1 || ua.indexOf( 'opera' ) > -1 || ua.indexOf( 'msie' ) > -1 ) &&
        document.getElementById && window.addEventListener ) {

        window.addEventListener( 'hashchange', function() {
            var element = document.getElementById( location.hash.substring( 1 ) );

            if ( element ) {
                if ( ! /^(?:a|select|input|button|textarea)$/i.test( element.nodeName ) ) {
                    element.tabIndex = -1;
                }

                element.focus();
            }
        }, false );
    }
} )();