在 wordpress 子主题中添加两个侧边栏 [英] Adding two sidebars in wordpress child theme

查看:48
本文介绍了在 wordpress 子主题中添加两个侧边栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Wordpress 中,我想制作两个侧边栏.一个将在内容的左侧,另一个将在 twentyelven 主题的右侧(默认侧边栏).为此,我对我的 211 个子主题进行了一些自定义.在functions.php中我做了这个改变

 register_sidebar( 数组('名称' =>__( '左侧边栏', 'buygames' ),'id' =>'侧边栏-左','before_widget' =>'<aside id="%1$s" class="widget %2$s">','after_widget' =>"</一边>",'before_title' =>'<h3 class="widget-title">','after_title' =>'</h3>',) );

然后在 sidebar-page.php 我添加了这段代码

 

就在代码 get_header(); 之后和 <div id="primary">....</div> 之前.这工作正常,但我认为这是错误的方法.通过这样做,它将被硬编码.那么有人可以建议我在不进行任何硬编码的情况下做到这一点的好方法是什么?任何帮助和建议都将受到高度赞赏.

解决方案

您可以将两个侧边栏添加到子主题的 sidebar.php 中,并按 css 排列.

//你的侧边栏<div id="左侧边栏"><?php dynamic_sidebar('sidebar-left');?></div><!--#left-sidebar-->//原始侧边栏<div id="侧边栏"><?php dynamic_sidebar('侧边栏');?></div><!--#sidebar-->

一定要添加两个侧边栏,因为你的子主题的 sidebar.php 覆盖了原来的.

In Wordpress I want to make two sidebars. One will be in left hand side of the content and the other one will be in the right hand side (default sidebar) in twentyelven theme. For that I made little bit customization to my twentyeleven child theme. In functions.php I made this changes

 register_sidebar( array(
    'name' => __( 'Left Hand Sidebar', 'buygames' ),
    'id' => 'sidebar-left',
    'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    'after_widget' => "</aside>",
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>',
  ) );

Then in sidebar-page.php I added this code

 <div id="left-sidebar">
  <?php dynamic_sidebar( 'sidebar-left' ); ?>
  </div><!--#left-sidebar-->

just after the code get_header(); and before the <div id="primary">....</div>. This is working fine but I think this is the wrong method. By doing this it will be hard-coded. So can some one suggest me what will be the good way to do this without making any hard coding? Any help and suggestions will be highly appreciable.

解决方案

You can add both sidebars to the sidebar.php of your childtheme and arrange them per css.

// your sidebar
<div id="left-sidebar">
  <?php dynamic_sidebar( 'sidebar-left' ); ?>
</div><!--#left-sidebar-->
// original sidebar
<div id="sidebar">
  <?php dynamic_sidebar( 'sidebar' ); ?>
</div><!--#sidebar-->

Be sure to add both sidebars because the sidebar.php of your child theme overwrites the original one.

这篇关于在 wordpress 子主题中添加两个侧边栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆