Get_Sidear()在footer.php中不起作用

时间:2021-05-01 作者:posfan12

我搬家了get_sidebar(); 从…起header.phpfooter.php 但它不会显示在页面正文中最后一篇文章之后,而不是页脚之后。没有显示错误。我需要做什么才能让它工作?

功能。php

/**
 * Register widget area.
 *
 * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
 */
function isometricland_widgets_init() {
    register_sidebar( array(
        \'name\'          => esc_html__( \'Sidebar\', \'isometricland\' ),
        \'id\'            => \'sidebar-1\',
        \'description\'   => esc_html__( \'Add widgets here.\', \'isometricland\' ),
        \'before_widget\' => \'<section id="%1$s" class="widget %2$s">\',
        \'after_widget\'  => \'</section>\',
        \'before_title\'  => \'<h2 class="widget-title">\',
        \'after_title\'   => \'</h2>\',
    ) );
}
add_action( \'widgets_init\', \'isometricland_widgets_init\' );
页脚。php

<?php
    global $path_root, $page_title, $path_img, $path_ssi, $path_css, $path_jav;
    include_once($path_ssi . \'plugin-paypal.php\');
    include_once($path_ssi . \'plugin-sitesearch.php\');
    include_once($path_ssi . \'plugin-socialicons.php\');
    include_once($path_ssi . \'plugin-norml.php\');
?>
                </main>
                <!-- END PAGE CONTENTS -->
                <!-- START FOOTERS -->
                <footer>
                    <div id="footframe">
                        <small class="blk"><?php printf( __( \'Proudly powered by %s.\', \'isometricland\' ), \'WordPress\' ); ?> <?php printf( __( \'Theme: %1$s by Michael Horvath based on %2$s GPLv2 or later.\', \'isometricland\' ), \'isometricland\', \'<a href="http://underscores.me/" rel="designer">Underscores.me</a>\' ); ?></small>
                        <small class="blk">This page &copy; Copyright 2009 Michael Horvath. Last modified: <?php echo date("F d Y H:i:s", getlastmod()) ?>.</small>
                    </div>
<?php wp_footer(); //Crucial footer hook! ?>
                </footer>
                <!-- END FOOTERS -->
            </div>
            <!-- END MIDDLE PANE -->
            <!-- START SIDEBAR -->
            <div id="leftframe">
                <div id="sidebarframetop">
                    <div id="sidebar_widget">
<?php get_sidebar(\'sidebar-1\'); ?>
                    </div>
                </div>
                <div id="sidebarframebot">
                    <div id="file_paypal">
<?php //echo writePaypalDonate(); ?>
                    </div>
                    <div id="file_search">
<?php //echo writeSiteSearchForm(); ?>
                    </div>
                    <div id="file_social">
<?php echo writeSocialIcons(); ?>
                    </div>
                    <div id="file_norml">
<?php //echo writeNormlLogo(); ?>
                    </div>
                </div>
            </div>
            <!-- END SIDEBAR -->
        </div>
    </body>
</html>
呈现的HTML:

                </main>
                <!-- END PAGE CONTENTS -->
                <!-- START FOOTERS -->
                <footer>
                    <div id="footframe">
                        <small class="blk">Proudly powered by WordPress. Theme: isometricland by Michael Horvath based on <a href="http://underscores.me/" rel="designer">Underscores.me</a> GPLv2 or later.</small>
                        <small class="blk">This page &copy; Copyright 2009 Michael Horvath. Last modified: February 06 2020 17:03:12.</small>
                    </div>
<script type="text/javascript">(function(a,d){if(a._nsl===d){a._nsl=[];var c=function(){if(a.jQuery===d)setTimeout(c,33);else{for(var b=0;b<a._nsl.length;b++)a._nsl[b].call(a,a.jQuery);a._nsl={push:function(b){b.call(a,a.jQuery)}}}};c()}})(window);</script><script type=\'text/javascript\' src=\'https://isometricland.net/blog/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/scripts/shCore.js?ver=3.0.9b\' id=\'syntaxhighlighter-core-js\'></script>
<script type=\'text/javascript\' src=\'https://isometricland.net/blog/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/scripts/shBrushCss.js?ver=3.0.9b\' id=\'syntaxhighlighter-brush-css-js\'></script>
<script type=\'text/javascript\'>
    (function(){
        var corecss = document.createElement(\'link\');
        var themecss = document.createElement(\'link\');
        var corecssurl = "https://isometricland.net/blog/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/styles/shCore.css?ver=3.0.9b";
        if ( corecss.setAttribute ) {
                corecss.setAttribute( "rel", "stylesheet" );
                corecss.setAttribute( "type", "text/css" );
                corecss.setAttribute( "href", corecssurl );
        } else {
                corecss.rel = "stylesheet";
                corecss.href = corecssurl;
        }
        document.head.appendChild( corecss );
        var themecssurl = "https://isometricland.net/blog/wp-content/plugins/syntaxhighlighter/syntaxhighlighter3/styles/shThemeFadeToGrey.css?ver=3.0.9b";
        if ( themecss.setAttribute ) {
                themecss.setAttribute( "rel", "stylesheet" );
                themecss.setAttribute( "type", "text/css" );
                themecss.setAttribute( "href", themecssurl );
        } else {
                themecss.rel = "stylesheet";
                themecss.href = themecssurl;
        }
        document.head.appendChild( themecss );
    })();
    SyntaxHighlighter.config.strings.expandSource = \'+ expand source\';
    SyntaxHighlighter.config.strings.help = \'?\';
    SyntaxHighlighter.config.strings.alert = \'SyntaxHighlighter\\n\\n\';
    SyntaxHighlighter.config.strings.noBrush = \'Can\\\'t find brush for: \';
    SyntaxHighlighter.config.strings.brushNotHtmlScript = \'Brush wasn\\\'t configured for html-script option: \';
    SyntaxHighlighter.defaults[\'class-name\'] = \'syntax\';
    SyntaxHighlighter.defaults[\'pad-line-numbers\'] = true;
    SyntaxHighlighter.all();

    // Infinite scroll support
    if ( typeof( jQuery ) !== \'undefined\' ) {
        jQuery( function( $ ) {
            $( document.body ).on( \'post-load\', function() {
                SyntaxHighlighter.highlight();
            } );
        } );
    }
</script>
<script type=\'text/javascript\' src=\'https://isometricland.net/blog/wp-content/themes/isometricland/js/navigation.js?ver=20151215\' id=\'isometricland-navigation-js\'></script>
<script type=\'text/javascript\' src=\'https://isometricland.net/blog/wp-content/themes/isometricland/js/skip-link-focus-fix.js?ver=20151215\' id=\'isometricland-skip-link-focus-fix-js\'></script>
<script type=\'text/javascript\' src=\'https://isometricland.net/blog/wp-includes/js/wp-embed.min.js?ver=5.7.1\' id=\'wp-embed-js\'></script>
<script type="text/javascript">(function (undefined) {var _targetWindow ="prefer-popup";
window.NSLPopup = function (url, title, w, h) {
    var userAgent = navigator.userAgent,
        mobile = function () {
            return /\\b(iPhone|iP[ao]d)/.test(userAgent) ||
                /\\b(iP[ao]d)/.test(userAgent) ||
                /Android/i.test(userAgent) ||
                /Mobile/i.test(userAgent);
        },
        screenX = window.screenX !== undefined ? window.screenX : window.screenLeft,
        screenY = window.screenY !== undefined ? window.screenY : window.screenTop,
        outerWidth = window.outerWidth !== undefined ? window.outerWidth : document.documentElement.clientWidth,
        outerHeight = window.outerHeight !== undefined ? window.outerHeight : document.documentElement.clientHeight - 22,
        targetWidth = mobile() ? null : w,
        targetHeight = mobile() ? null : h,
        V = screenX < 0 ? window.screen.width + screenX : screenX,
        left = parseInt(V + (outerWidth - targetWidth) / 2, 10),
        right = parseInt(screenY + (outerHeight - targetHeight) / 2.5, 10),
        features = [];
    if (targetWidth !== null) {
        features.push(\'width=\' + targetWidth);
    }
    if (targetHeight !== null) {
        features.push(\'height=\' + targetHeight);
    }
    features.push(\'left=\' + left);
    features.push(\'top=\' + right);
    features.push(\'scrollbars=1\');

    var newWindow = window.open(url, title, features.join(\',\'));

    if (window.focus) {
        newWindow.focus();
    }

    return newWindow;
};

var isWebView = null;

function checkWebView() {
    if (isWebView === null) {
        function _detectOS(ua) {
            if (/Android/.test(ua)) {
                return "Android";
            } else if (/iPhone|iPad|iPod/.test(ua)) {
                return "iOS";
            } else if (/Windows/.test(ua)) {
                return "Windows";
            } else if (/Mac OS X/.test(ua)) {
                return "Mac";
            } else if (/CrOS/.test(ua)) {
                return "Chrome OS";
            } else if (/Firefox/.test(ua)) {
                return "Firefox OS";
            }
            return "";
        }

        function _detectBrowser(ua) {
            var android = /Android/.test(ua);

            if (/CriOS/.test(ua)) {
                return "Chrome for iOS";
            } else if (/Edge/.test(ua)) {
                return "Edge";
            } else if (android && /Silk\\//.test(ua)) {
                return "Silk";
            } else if (/Chrome/.test(ua)) {
                return "Chrome";
            } else if (/Firefox/.test(ua)) {
                return "Firefox";
            } else if (android) {
                return "AOSP";
            } else if (/MSIE|Trident/.test(ua)) {
                return "IE";
            } else if (/Safari\\//.test(ua)) {
                return "Safari";
            } else if (/AppleWebKit/.test(ua)) {
                return "WebKit";
            }
            return "";
        }

        function _detectBrowserVersion(ua, browser) {
            if (browser === "Chrome for iOS") {
                return _getVersion(ua, "CriOS/");
            } else if (browser === "Edge") {
                return _getVersion(ua, "Edge/");
            } else if (browser === "Chrome") {
                return _getVersion(ua, "Chrome/");
            } else if (browser === "Firefox") {
                return _getVersion(ua, "Firefox/");
            } else if (browser === "Silk") {
                return _getVersion(ua, "Silk/");
            } else if (browser === "AOSP") {
                return _getVersion(ua, "Version/");
            } else if (browser === "IE") {
                return /IEMobile/.test(ua) ? _getVersion(ua, "IEMobile/") :
                    /MSIE/.test(ua) ? _getVersion(ua, "MSIE ")
                        :
                        _getVersion(ua, "rv:");
            } else if (browser === "Safari") {
                return _getVersion(ua, "Version/");
            } else if (browser === "WebKit") {
                return _getVersion(ua, "WebKit/");
            }
            return "0.0.0";
        }

        function _getVersion(ua, token) {
            try {
                return _normalizeSemverString(ua.split(token)[1].trim().split(/[^\\w\\.]/)[0]);
            } catch (o_O) {
            }
            return "0.0.0";
        }

        function _normalizeSemverString(version) {
            var ary = version.split(/[\\._]/);
            return (parseInt(ary[0], 10) || 0) + "." +
                (parseInt(ary[1], 10) || 0) + "." +
                (parseInt(ary[2], 10) || 0);
        }

        function _isWebView(ua, os, browser, version, options) {
            switch (os + browser) {
                case "iOSSafari":
                    return false;
                case "iOSWebKit":
                    return _isWebView_iOS(options);
                case "AndroidAOSP":
                    return false;
                case "AndroidChrome":
                    return parseFloat(version) >= 42 ? /; wv/.test(ua) : /\\d{2}\\.0\\.0/.test(version) ? true : _isWebView_Android(options);
            }
            return false;
        }

        function _isWebView_iOS(options) {
            var document = (window["document"] || {});

            if ("WEB_VIEW" in options) {
                return options["WEB_VIEW"];
            }
            return !("fullscreenEnabled" in document || "webkitFullscreenEnabled" in document || false);
        }

        function _isWebView_Android(options) {
            if ("WEB_VIEW" in options) {
                return options["WEB_VIEW"];
            }
            return !("requestFileSystem" in window || "webkitRequestFileSystem" in window || false);
        }

        var options = {};
        var nav = window.navigator || {};
        var ua = nav.userAgent || "";
        var os = _detectOS(ua);
        var browser = _detectBrowser(ua);
        var browserVersion = _detectBrowserVersion(ua, browser);

        isWebView = _isWebView(ua, os, browser, browserVersion, options);
    }

    return isWebView;
}

function isAllowedWebViewForUserAgent() {
    var nav = window.navigator || {};
    var ua = nav.userAgent || "";
    if (/Instagram/.test(ua)) {
        /*Instagram WebView*/
        return true;
    } else if (/FBAV/.test(ua) || /FBAN/.test(ua)) {
        /*Facebook WebView*/
        return true;
    }

    return false;
}

window._nsl.push(function ($) {

    window.nslRedirect = function (url) {
        $(\'<div style="position:fixed;z-index:1000000;left:0;top:0;width:100%;height:100%;"></div>\').appendTo(\'body\');
        window.location = url;
    };

    var targetWindow = _targetWindow || \'prefer-popup\',
        lastPopup = false;

    $(document.body).on(\'click\', \'a[data-plugin="nsl"][data-action="connect"],a[data-plugin="nsl"][data-action="link"]\', function (e) {
        if (lastPopup && !lastPopup.closed) {
            e.preventDefault();
            lastPopup.focus();
        } else {

            var $target = $(this),
                href = $target.attr(\'href\'),
                success = false;
            if (href.indexOf(\'?\') !== -1) {
                href += \'&\';
            } else {
                href += \'?\';
            }
            var redirectTo = $target.data(\'redirect\');
            if (redirectTo === \'current\') {
                href += \'redirect=\' + encodeURIComponent(window.location.href) + \'&\';
            } else if (redirectTo && redirectTo !== \'\') {
                href += \'redirect=\' + encodeURIComponent(redirectTo) + \'&\';
            }

            if (targetWindow !== \'prefer-same-window\' && checkWebView()) {
                targetWindow = \'prefer-same-window\';
            }

            if (targetWindow === \'prefer-popup\') {

                lastPopup = NSLPopup(href + \'display=popup\', \'nsl-social-connect\', $target.data(\'popupwidth\'), $target.data(\'popupheight\'));
                if (lastPopup) {
                    success = true;
                    e.preventDefault();
                }
            } else if (targetWindow === \'prefer-new-tab\') {
                var newTab = window.open(href + \'display=popup\', \'_blank\');
                if (newTab) {
                    if (window.focus) {
                        newTab.focus();
                    }
                    success = true;
                    e.preventDefault();
                }
            }

            if (!success) {
                window.location = href;
                e.preventDefault();
            }
        }
    });

    var googleLoginButton = $(\'a[data-plugin="nsl"][data-provider="google"]\');
    if (googleLoginButton.length && checkWebView() && !isAllowedWebViewForUserAgent()) {
        googleLoginButton.remove();
    }
});})();</script>               </footer>
                <!-- END FOOTERS -->
            </div>
            <!-- END MIDDLE PANE -->
            <!-- START SIDEBAR -->
            <div id="leftframe">
                <div id="sidebarframetop">
                    <div id="sidebar_widget">
                    </div>
                </div>
                <div id="sidebarframebot">
                    <div id="file_paypal">
                    </div>
                    <div id="file_search">
                    </div>
                    <div id="file_social">
<div class="social" title="DeviantArt"  ><a href="https://posfan12.deviantart.com/"             target="_blank"><img class="nomagnify" style="margin:0px;" src="https://isometricland.net/images/icon_deviantart.png"   alt="DeviantArt"    /></a></div>
<div class="social" title="Facebook"    ><a href="https://www.facebook.com/michael.horvath.35"          target="_blank"><img class="nomagnify" style="margin:0px;" src="https://isometricland.net/images/icon_facebook.png" alt="Facebook"      /></a></div>
<div class="social" title="Flickr"  ><a href="https://www.flickr.com/photos/108839565@N04/"         target="_blank"><img class="nomagnify" style="margin:0px;" src="https://isometricland.net/images/icon_flickr.png"   alt="Flickr"        /></a></div>
<div class="social" title="GitHub"  ><a href="https://github.com/mjhorvath"                 target="_blank"><img class="nomagnify" style="margin:0px;" src="https://isometricland.net/images/icon_github.png"   alt="GitHub"        /></a></div>
<br/>
<div class="social" title="Goodreads"   ><a href="https://www.goodreads.com/user/show/67971043-michael-horvath" target="_blank"><img class="nomagnify" style="margin:0px;" src="https://isometricland.net/images/icon_goodreads.png"    alt="Goodreads"     /></a></div>
<div class="social" title="LinkedIn"    ><a href="https://www.linkedin.com/in/michael-horvath-45547a116/"   target="_blank"><img class="nomagnify" style="margin:0px;" src="https://isometricland.net/images/icon_linkedin.png" alt="LinkedIn"      /></a></div>
<div class="social" title="Spotify" ><a href="https://open.spotify.com/user/f1703yjwz5hxcrndycvbjfwbl"  target="_blank"><img class="nomagnify" style="margin:0px;" src="https://isometricland.net/images/icon_spotify.png"  alt="Spotify"       /></a></div>
<div class="social" title="Wikipedia"   ><a href="https://en.wikipedia.org/wiki/User:Datumizer"         target="_blank"><img class="nomagnify" style="margin:0px;" src="https://isometricland.net/images/icon_wikipedia.png"    alt="Wikipedia"     /></a></div>
                    </div>
                    <div id="file_norml">
                    </div>
                </div>
            </div>
            <!-- END SIDEBAR -->
        </div>
    </body>
</html>

2 个回复
最合适的回答,由SO网友:Jacob Peattie 整理而成

你需要阅读文档,get_sidebar():

包含主题的边栏模板,或者如果指定了名称,则将包含专门的边栏。

其目的是加载sidebar.php. 它不输出小部件。要输出您需要使用的小部件dynamic_sidebar():

<?php dynamic_sidebar( \'sidebar-1\' ); ?>
将输出添加到该小部件区域的小部件。这在the documentation.

SO网友:Pixelsmith

如果你想把它放在页脚上,就把它放在页脚上。

            </main>
            <!-- END PAGE CONTENTS -->
            <!-- START FOOTERS -->
            <footer>
              <div id="footframe">
              </div>                    
              <!-- START SIDEBAR -->
              <div id="leftframe">
               <div id="sidebarframetop">
                <div id="sidebar_widget">
                  <?php get_sidebar(); ?>
                 </div>
                </div>
               </div>
              <!-- END SIDEBAR -->
             <?php wp_footer(); //Crucial footer hook! ?>
            </footer>
            <!-- END FOOTERS -->