首页 > 解决方案 > 将 Wordpress 侧边栏从页脚移到另一侧

问题描述

我正在尝试使用 TwentyTwenty 主题在我的 WordPress 网站的右侧添加一个小部件区域。小部件当前正在显示,但它位于页面底部。谁能给我一些关于需要更改哪些 PHP 或 CSS 代码以使其一直显示在右侧而不是仅在底部的指示?

侧边栏目前的显示截图(红色框)

我已按照这些说明操作,并在我的子主题functions.php文件中成功注册了一个侧边栏,创建了自己的sidebar-right.php文件,并将其包含在我的singular.php模板中。这三个文件的代码分别是:

<?php if ( function_exists('register_sidebar') ) {
   register_sidebar(array(
    'name'          => 'Right Sidebar',
    'id'            => 'right-sidebar',
    'description'   => 'Appears as the right sidebar',
    'before_widget' => '<div style="height: 280px"></div><li id="%1$s" class="widget %2$s">',
    'after_widget'  => '</li>',
    'before_title ' => '<h2 class="widgettitle">',
    'after_title'   => '</h2>',
));
} ?>
<div id="sidebar">
   <ul>
      <?php
      if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('right-sidebar') ) :
      endif; ?>
   </ul>
</div>
<?php get_header();?>
<main id="site-content" role="main">

    <?php
    if ( have_posts() ) {
        while ( have_posts() ) {
            the_post();
            get_template_part( 'template-parts/content', get_post_type() );
        }
    } ?>

</main><!-- #site-content --> 
<?php get_sidebar('right'); ?>
<?php get_template_part( 'template-parts/footer-menus-widgets' ); ?>
<?php get_footer(); ?>

非常感谢!

标签: phphtmlcsswordpress

解决方案


推荐阅读