2013-03-19 56 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')。

相關問題