在任意位置插入小工具 wordpress主题修改 让主题支持小工具

输入以下代码到 /wp-content/theme/themename/functions.php 如果没有可以自己手动创建一个。

 

<?php 
if (function_exists('register_sidebar')) { 
register_sidebar(array( 
'name' => '边栏1', // 侧边栏 1 的名称 
'before_widget' => '<li>', // widget 的开始标签 
'after_widget' => '</li>', // widget 的结束标签 
'before_title' => '<h3>', // 标题的开始标签 
'after_title' => '</h3>'// 标题的结束标签
 
));
 
register_sidebar(array( 
'name' => '边栏2', // 侧边栏 2 的名称 
'before_widget' => '<li>', // widget 的开始标签 
'after_widget' => '</li>', // widget 的结束标签 
'before_title' => '<h3>', // 标题的开始标签 
'after_title' => '</h3>'// 标题的结束标签
 
));
 
register_sidebar(array( 
'name' => '边栏3', // 侧边栏 3 的名称 
'before_widget' => '<li>', // widget 的开始标签 
'after_widget' => '</li>', // widget 的结束标签 
'before_title' => '<h3>', // 标题的开始标签 
'after_title' => '</h3>'// 标题的结束标签
 
));
 
register_sidebar(array( 
'name' => '边栏4', // 侧边栏 4 的名称 
'before_widget' => '<li>', // widget 的开始标签 
'after_widget' => '</li>', // widget 的结束标签 
'before_title' => '<h3>', // 标题的开始标签 
'after_title' => '</h3>'// 标题的结束标签
 
)); 
} 
?>

 

1之后我们只需要在想要添加小工具的地方数据以下代码。2

<?php 
if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('边栏名称3')): 
?> 
<?php 
endif; 

?>3

 

 

Last modified onSunday, 23 December 2012 14:45

( ! ) Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php on line 169
Call Stack
#TimeMemoryFunctionLocation
10.0022413448{main}( ).../index.php:0
20.11064264136Joomla\CMS\Application\SiteApplication->execute( ).../index.php:49
30.11064264136Joomla\CMS\Application\SiteApplication->doExecute( ).../CMSApplication.php:196
40.363911455488Joomla\CMS\Application\SiteApplication->dispatch( ).../SiteApplication.php:233
50.364911480472Joomla\CMS\Component\ComponentHelper::renderComponent( ).../SiteApplication.php:194
60.366011535800Joomla\CMS\Component\ComponentHelper::executeComponent( ).../ComponentHelper.php:377
70.366311563200require_once( '/var/www/vhosts/shan.info/httpdocs/components/com_k2/k2.php' ).../ComponentHelper.php:402
80.379511962832K2ControllerItem->execute( ).../k2.php:64
90.379511962832K2ControllerItem->display( ).../BaseController.php:710
100.391812613536K2ControllerItem->display( ).../item.php:78
110.391812613536K2ControllerItem->display( ).../controller.php:19
120.395712984576Joomla\CMS\Cache\Controller\ViewController->get( ).../BaseController.php:663
130.398013004944K2ViewItem->display( ).../ViewController.php:102
140.467315781544K2ViewItem->display( ).../view.html.php:742
150.467315781544K2ViewItem->loadTemplate( ).../HtmlView.php:230
160.470115954480include( '/var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php' ).../HtmlView.php:701

( ! ) Notice: Only variables should be assigned by reference in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php on line 478
Call Stack
#TimeMemoryFunctionLocation
10.0022413448{main}( ).../index.php:0
20.11064264136Joomla\CMS\Application\SiteApplication->execute( ).../index.php:49
30.11064264136Joomla\CMS\Application\SiteApplication->doExecute( ).../CMSApplication.php:196
40.363911455488Joomla\CMS\Application\SiteApplication->dispatch( ).../SiteApplication.php:233
50.364911480472Joomla\CMS\Component\ComponentHelper::renderComponent( ).../SiteApplication.php:194
60.366011535800Joomla\CMS\Component\ComponentHelper::executeComponent( ).../ComponentHelper.php:377
70.366311563200require_once( '/var/www/vhosts/shan.info/httpdocs/components/com_k2/k2.php' ).../ComponentHelper.php:402
80.379511962832K2ControllerItem->execute( ).../k2.php:64
90.379511962832K2ControllerItem->display( ).../BaseController.php:710
100.391812613536K2ControllerItem->display( ).../item.php:78
110.391812613536K2ControllerItem->display( ).../controller.php:19
120.395712984576Joomla\CMS\Cache\Controller\ViewController->get( ).../BaseController.php:663
130.398013004944K2ViewItem->display( ).../ViewController.php:102
140.467315781544K2ViewItem->display( ).../view.html.php:742
150.467315781544K2ViewItem->loadTemplate( ).../HtmlView.php:230
160.470115954480include( '/var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php' ).../HtmlView.php:701
back to top