[英]How to create and active Left sidebar on Wordpress theme?
I can't create left sidebar.我无法创建左侧边栏。
I created a file into child theme folder: sidebar-left.php:我在子主题文件夹中创建了一个文件:sidebar-left.php:
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly ?>
<aside class="sidebar">
<!-- SIDEBAR WIDGET AREA -->
<?php if ( is_active_sidebar( 'lhsidebar' ) ) : ?>
<?php dynamic_sidebar( 'lhsidebar' ); ?>
<?php else : ?>
<p><?php esc_html_e('No widgets added', 'rehub-theme'); ?></p>
<?php endif; ?>
</aside>
Then, I have added this code into child theme's function.php :然后,我将此代码添加到子主题的function.php 中:
// Left SideBar
register_sidebar( array(
'name' => esc_html__( 'Left Sidebar', 'rehub' ),
'id' => 'lhsidebar',
'description' => esc_html__( 'Add widgets here.', 'rehub' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
) );
But where should I put the get_sidebar('sidebar-left')
?但是我应该把
get_sidebar('sidebar-left')
放在哪里?
You have to call the sidebar inside any template of your child theme either by using the get_sidebar()
function:您必须使用
get_sidebar()
函数在子主题的任何模板中调用侧边栏:
<?php get_sidebar('left'); ?>
Note: the name of the file without sidebar-
part at the begin of the name as mentionned in the doc .注意:文件的名称在名称的开头没有
sidebar-
部分,如文档中所述。
Either by using the get_template_part()
function if your template file is not in the same directory as the sidebar file.如果您的模板文件与侧边栏文件不在同一目录中,则使用
get_template_part()
函数。
<?php get_template_part( 'sidebar-templates/sidebar', 'left' ); ?>
Note: here the full name of the sidebar is mentionned in the function, as well as its path from the root of the child-theme, cf doc .注意:这里在函数中提到了侧边栏的全名,以及它从子主题的根开始的路径,cf doc 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.