2013-03-19 76 views
7

我已经安装了一个名为Translator Box的pludgin,我使用它的短代码并将它放到我的wordpress主题header.php中。如何将小部件添加到wordpress中的header.php?

[translation_box languages="english,russian,german,spanish,french,chinese" width="100%" height="200px" bgcolor="white" txtcolor="#000000"] 

但是不起作用!

它还在小部件的Enabled小部件中生成小部件。在header.php中使用可以调用小部件的代码时有没有办法?谢谢。

回答

2

使用do_shortcode

<?php echo do_shortcode($content) ?> 
+0

有没有办法找到pludgin shortcode?谢谢你 – down1337 2013-03-19 11:06:57

+1

大多数插件的文档都有简码。如果没有,你可以通过插件的PHP文件查看“add_shortcode”。格式将是add_shortcode('short_code_name','function_name')。 – 2013-03-19 11:09:44

15

你可以在你的header.php定义的一部分,显示部件。 在你的functions.php做这样的事情:

function my_widgets_init() { 

register_sidebar(array(
    'name' => __('Main Sidebar', 'your-theme'), 
    'id' => 'sidebar-1', 
    'before_widget' => '<div id="%1$s" class="widget %2$s">', 
    'after_widget' => "</div>", 
    'before_title' => '<h3>', 
    'after_title' => '</h3>', 
)); 

register_sidebar(array(
    'name' => __('Header Area', 'your-theme'), 
    'id' => 'sidebar-2', 
    'description' => __('An optional widget area for your site header', 'your-theme'), 
    'before_widget' => '<div id="%1$s" class="headwidget %2$s">', 
    'after_widget' => "</div>", 
    'before_title' => '<h3>', 
    'after_title' => '</h3>', 
)); 
} 
add_action('widgets_init', 'my_widgets_init'); 

例如第一部分将在侧边栏小部件区域,并在报头中的第二小部件区域。

现在包括在您的header.php文件:

<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar-2')) : ?> 
<?php endif; ?> 

在您的小部件应。

在您的管理界面中,您现在应该有2个可以填充小部件的区域('Main Sidebar'和'Header Area')。

相关问题