在特定 WordPress 主题中添加第二个侧边栏

发布于 2024-08-04 10:05:16 字数 1667 浏览 5 评论 0原文

我学会了如何添加额外的侧边栏现在我需要弄清楚如何添加除了主题 Librio ( wordpress.org/extend/themes/librio ) 中已显示的侧边栏之外,还有一个额外的侧边栏。

我完全不知道该去哪里寻找。该代码纯粹是混乱的并且不言自明。

我的 sidebar.php 包含以下代码:

<div id="idontknow">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar1') ) : ?>
<?php endif; ?>
</div>

现在,如果我复制并添加相同的代码,但使用“sidebar2”,我得到的只是在第一个侧边栏内显示的第二个侧边栏。

<div id="idontknow">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar1') ) : ?>
<?php endif; ?>
</div>

<div id="ireallydont">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar2') ) : ?>
<?php endif; ?>
</div>

我不想要这样。我想要两个并排的独立侧边栏。有人可以帮帮我吗?

我尝试使用 CSS 和 id=leftsidebar 和 id=rightsidebar 来过期,但它根本不起作用。

再次澄清一下: 我有 2 个侧边栏!我什至在functions.php 中得到了正确的代码

if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'sidebar1',
    'before_widget' => '<div class="block">',
    'after_widget' => '</div>',
    'before_title' => '<h3 class="widgettitle">',
    'after_title' => '</h3>',
));
register_sidebar(array('name'=>'sidebar2',
    'before_widget' => '<div class="block">',
    'after_widget' => '</div>',
    'before_title' => '<h3 class="widgettitle">',
    'after_title' => '</h3>',
));

问题是,如上所述,第二个新创建的侧边栏显示在第一个侧边栏中。我想要修改主题,以便有 2 个独立的侧边栏。

I learned how to add additional sidebars now I need to figure out how to add an extra sidebar besides the one already displayed in the theme Librio ( wordpress.org/extend/themes/librio ).

I absolutely have no idea where to look. The code is pure chaos and not self explanatory.

My sidebar.php contains the following code:

<div id="idontknow">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar1') ) : ?>
<?php endif; ?>
</div>

Now if I duplicate and add the same code but with 'sidebar2' all I get is the 2nd sidebar being displayed INSIDE the 1st sidebar.

<div id="idontknow">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar1') ) : ?>
<?php endif; ?>
</div>

<div id="ireallydont">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar2') ) : ?>
<?php endif; ?>
</div>

I don't want that. I want 2 separate sidebars side by side. Can somebody help me out, pretty please?

I tried to expirement with CSS and id=leftsidebar and id=rightsidebar, but it simply doesnt work.

Just to clarify again:
I have 2 sidebars! I've even got the correct code in functions.php

if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'sidebar1',
    'before_widget' => '<div class="block">',
    'after_widget' => '</div>',
    'before_title' => '<h3 class="widgettitle">',
    'after_title' => '</h3>',
));
register_sidebar(array('name'=>'sidebar2',
    'before_widget' => '<div class="block">',
    'after_widget' => '</div>',
    'before_title' => '<h3 class="widgettitle">',
    'after_title' => '</h3>',
));

The problem is, like mentioned, the 2nd newly created sidebar is shown inside the 1st sidebar. I want the theme modified so that I have 2 separate sidebars.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

放飞的风筝 2024-08-11 10:05:16

您必须注册第二个侧边栏。

在你的主题文件夹中创建一个文件 functions.php (也许这个文件已经存在)并添加以下代码:

    <?php
        register_sidebar(array('name'=>'sidebar'));
        register_sidebar(array('name'=>'sidebar2'));
    ?>

现在,如果你转到你的 WordPress 管理部分,你应该看到有 2 个侧边栏可用,其中您可以添加小部件。

You have to register a second sidebar.

create a file functions.php (maybe this file already exists) in your theme folder en add the following code:

    <?php
        register_sidebar(array('name'=>'sidebar'));
        register_sidebar(array('name'=>'sidebar2'));
    ?>

Now if you go to your wordpress admin section, you should see that there are 2 sidebars available where you can add widgets to.

孤独患者 2024-08-11 10:05:16

这更多的是 CSS 问题。我已经复制了您的设置并完成了以下操作以使两列正常工作。

我的 sidebar.php 是:

<div id="sidebar">
  <div id="idontknow">
  <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar1') ) : ?>
  <?php endif; ?>
  </div>
  <div id="ireallydont">
  <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar2') ) : ?>
  <?php endif; ?>
  </div>
</div>

我已在functions.php 中注册了两个侧边栏(如 Dextro 建议),并确认它们都可以工作并在另一个下方显示一个。

然后我在 style.css 中进行了以下宽度更改:

  • 在第 173 行,我更改了 #content 的
    在第 303 行将宽度更改为 570px
  • ,我将

    侧边栏的宽度更改为 300px

然后我添加了一个新的 CSS 规则:

#sidebar #idontknow,
#sidebar #ireallydont {
    width: 150px;float: left;
}

现在我有两列边。您可能想要调整宽度,并且肯定想要修复侧边栏背景图像。

This is more of a CSS issue than anything else. I've replicated your setup and done the following to get two columns working.

My sidebar.php is:

<div id="sidebar">
  <div id="idontknow">
  <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar1') ) : ?>
  <?php endif; ?>
  </div>
  <div id="ireallydont">
  <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar2') ) : ?>
  <?php endif; ?>
  </div>
</div>

I've registered both sidebars in functions.php (as Dextro suggested) and confirm they both work and show one below the other.

Then I made the following width changes in style.css:

  • at line 173, I changed #content's
    width to 570px
  • at line 303, I changed

    sidebar's width to 300px

Then I added a new CSS rule:

#sidebar #idontknow,
#sidebar #ireallydont {
    width: 150px;float: left;
}

Now I have two columns side. You may want to adjust the widths and you'll definitely want to fix the sidebar background image.

双手揣兜 2024-08-11 10:05:16

您是否尝试过将第二个侧边栏 div 的 id 更改为 id="sidebar2" ?如果不查看站点/代码,很难判断,但 CSS 中可能存在某些内容导致两个侧边栏重叠。要么是,要么第一个没有正确关闭。

Have you tried changing the id of your second sidebar div to id="sidebar2"? It's very hard to tell without seeing the site/code but there may be something in the CSS which is causing the two sidebars to overlap. Either that, or the first isn't being closed properly.

伤痕我心 2024-08-11 10:05:16

您是否将侧边栏 div 放入 librio 的侧边栏 div 中?

换句话说,您的 sidebar.php 看起来像这样吗?

<div id="sidebar">
    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar1') ) : ?>

    <!-- default librio sidebar stuff goes here -->

    <?php endif; ?>

    <div id="sidebar2">
        <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar1') ) : ?>

        <!-- second sidebar stuff goes here -->

        <?php endif; ?>
    </div>
</div>

当我这样做时,第二个侧边栏作为默认 librio 侧边栏的一部分出现。当我将

内容移到

Did you put your sidebar divs inside the librio's sidebar div?

In other words, does your sidebar.php look like this?

<div id="sidebar">
    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar1') ) : ?>

    <!-- default librio sidebar stuff goes here -->

    <?php endif; ?>

    <div id="sidebar2">
        <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar1') ) : ?>

        <!-- second sidebar stuff goes here -->

        <?php endif; ?>
    </div>
</div>

When I did that, the second sidebar appeared as part of the default librio sidebar. When I moved the <div id="sidebar2"> stuff outside <div id="sidebar">, the second sidebar content appeared at the bottom of the page. You'll need to modify the CSS to move it somewhere else.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文