在 Wordpress 主题中添加 3 列动态小部件页脚

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12091407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:59:28  来源:igfitidea点击:

Add a 3 column dynamic widget footer in Wordpress theme

wordpressdynamicwidgetfooter

提问by Paul

My wordpress theme does not have a widgetised footer area. All there is is just a

我的 wordpress 主题没有小部件页脚区域。一切都只是一个

footer text

页脚文本

在页脚中。

I want to be able to add widgets in my footer from the widgets area in dashboard, such as blogroll, site pages, recent posts etc. I want the footer to be 3 columns.

我希望能够从仪表板的小部件区域在我的页脚中添加小部件,例如 blogroll、站点页面、最近的帖子等。我希望页脚为 3 列。

How can I do this? cheers

我怎样才能做到这一点?干杯

回答by McNab

You'd first of all register your widget areas in functions.php;

您首先在functions.php 中注册您的小部件区域;

/* REGISTER WIDGETS ------------------------------------------------------------*/

if (function_exists('register_sidebar')) {
    register_sidebar(array(
        'name' => 'Footer Left',
        'id'   => 'footer-left-widget',
        'description'   => 'Left Footer widget position.',
        'before_widget' => '<div id="%1$s">',
        'after_widget'  => '</div>',
        'before_title'  => '<h2>',
        'after_title'   => '</h2>'
    ));

    register_sidebar(array(
        'name' => 'Footer Center',
        'id'   => 'footer-center-widget',
        'description'   => 'Centre Footer widget position.',
        'before_widget' => '<div id="%1$s">',
        'after_widget'  => '</div>',
        'before_title'  => '<h2>',
        'after_title'   => '</h2>'
    ));

    register_sidebar(array(
        'name' => 'Footer Right',
        'id'   => 'footer-right-widget',
        'description'   => 'Right Footer widget position.',
        'before_widget' => '<div id="%1$s">',
        'after_widget'  => '</div>',
        'before_title'  => '<h2>',
        'after_title'   => '</h2>'
    ));


}

Then in your footer.php file you'd have something like this;

然后在你的 footer.php 文件中你会有这样的东西;

    <!-- footer -->
    <div id="mainfooter">

        <!-- 1/3 -->
        <div class="four columns">
            <?php if ( !function_exists( 'dynamic_sidebar' ) || !dynamic_sidebar('footer-left-widget') ) ?>
        </div>
        <!-- /End 1/3 -->
        <!-- 2/3 -->
        <div class="four columns">
            <?php if ( !function_exists( 'dynamic_sidebar' ) || !dynamic_sidebar('footer-center-widget') ) ?>
        </div>
        <!-- /End 2/3 -->
        <!-- 3/3 -->
        <div class="four columns">
            <?php if ( !function_exists( 'dynamic_sidebar' ) || !dynamic_sidebar('footer-right-widget') ) ?>
        </div>
        <!-- /End 3/3 -->

    </div>
    <!-- /End Footer -->

回答by Saranya Arun

First put this line of codes in function.php

先把这行代码放在function.php中

if ( function_exists('register_sidebar') ) {
    register_sidebar(); 

    register_sidebars(3, array('name'=>'Footer %d'));
} 

Add this to your footer.php file

将此添加到您的 footer.php 文件中

<div id="footerwidgets">
 <div id="footer-left"> 

 <ul> <?php if ( !function_exists('dynamic_sidebar') ||
    !dynamic_sidebar('footer 1') ) : ?> <li> <?php endif; ?> </ul>

 </div> 
<div id="footer-middle"> 

 <ul> <?php if ( !function_exists('dynamic_sidebar') ||
    !dynamic_sidebar('footer 2') ) : ?> <li> <?php endif; ?> </ul>

</div> 
<div id="footer-right"> 

 <ul> <?php if ( !function_exists('dynamic_sidebar') ||
 !dynamic_sidebar('footer 3') ) : ?> <li> <?php endif; ?> </ul>

 </div> 
</div> 
<br>
 <br clear="all" />