我已经搜索了很多,但似乎无法找到我应该保存我创建的小部件代码的位置。这有点莫名其妙。
有谁能告诉我应该在哪里保存我的小部件?
答案 0 :(得分:2)
我认为你已经开始搜索跳舞的猫...谷歌WordPress Create widget tutorial
首先在 wp-content / plugins 目录中创建一个新的.php文件。
答案 1 :(得分:0)
请按照以下步骤
<强> 1。注册页脚小部件区域
从WordPress主题编辑器中打开functions.php文件,然后搜索以下代码行:
register_sidebar
这应该会带你到你主题中注册了所有侧边栏的区域。
在其他侧边栏注册码的正下方添加以下代码块(我们告诉它注册3个页脚小部件区域):
register_sidebar( array(
'name' => 'Footer Sidebar 1',
'id' => 'footer-sidebar-1',
'description' => 'Appears in the footer area',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => 'Footer Sidebar 2',
'id' => 'footer-sidebar-2',
'description' => 'Appears in the footer area',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => 'Footer Sidebar 3',
'id' => 'footer-sidebar-3',
'description' => 'Appears in the footer area',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
<强> 2。在主题中显示页脚小部件区域
打开你的footer.php文件并在你想要显示页脚小部件的地方插入以下代码块(如果它们中有任何小部件,这将显示3个页脚小部件区域):
<div id="footer-sidebar" class="secondary">
<div id="footer-sidebar1">
<?php
if(is_active_sidebar('footer-sidebar-1')){
dynamic_sidebar('footer-sidebar-1');
}
?>
</div>
<div id="footer-sidebar2">
<?php
if(is_active_sidebar('footer-sidebar-2')){
dynamic_sidebar('footer-sidebar-2');
}
?>
</div>
<div id="footer-sidebar3">
<?php
if(is_active_sidebar('footer-sidebar-3')){
dynamic_sidebar('footer-sidebar-3');
}
?>
</div>
</div>
第3。根据自己的喜好设置页脚小部件区域的样式
将以下CSS代码块添加到主题的style.css文件中,以便为刚刚添加的页脚小部件添加一些基本样式。根据您的需求定制一点。我们的how to use firebug教程应该派上用场。
#footer-sidebar {
display:block;
height: 250px;
}
#footer-sidebar1 {
float: left;
width: 340px;
margin-left:5px;
margin-right:5px;
}
#footer-sidebar2 {
float: left;
width: 340px;
margin-right:5px;
}
#footer-sidebar3 {
float: left;
width: 340px;
}
答案 2 :(得分:0)
在function.php中添加此代码
if(function_exists('register_sidebar')) {
register_sidebar(array('name' => 'footer1',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4>', 'after_title' => '</h4>'
)
);
register_sidebar(array('name' => 'footer2',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h4>', 'after_title' => '</h4>'
)
);
}
在footer.php文件中添加此代码
<?php dynamic_sidebar('footer1') ; ?>
<?php dynamic_sidebar('footer2') ; ?>