调用wordpress小部件

时间:2013-06-28 18:03:08

标签: php wordpress widget

我在调用news小部件时遇到了一些问题。当我在标题中调用它时它工作正常,但在page.phphome.php等任何其他文件中都不起作用。这是简单的代码。

<?php  if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("news") ) : ?><?php endif; ?>

2 个答案:

答案 0 :(得分:1)

如果您想使用news功能显示dynamic_sidebar窗口小部件,请尝试使用

<?php  
    if ( function_exists('dynamic_sidebar') && dynamic_sidebar("news") ) :
    else :
     // static hard coded widgets
    endif;
?>

答案 1 :(得分:0)

您还可以在page.php中调用侧栏小部件,调用get_sidebar,如果您在新闻侧边栏中注册了小部件,则会加载sidebar-news.php,这样就可以简单地调用侧栏,这将加载所有小部件在这个侧栏中

<?php get_sidebar( 'news' ); ?>