doupao1530 2013-09-29 16:22
浏览 11
已采纳

如何允许用户更改窗口小部件标题颜色?

So I'm building this theme where I want to allow users to change the color of the background of the title of widgets. Therefore in functions.php, where I register the sidebar, I've got:

      'before_widget' => '',
      'after_widget' => '',
      'before_title' => '<div class="widget-header"><p>',
      'after_title' => '</p></div>',

To allow people to change the color of backround of the title I added:

'before title' => '<div class="widget-header" style="background: #ccc;"><p>'

And that still works. I created a theme options page where people can choose the color, and I changet the code to:

'before title' => '<div class="widget-header" style="background: <?php echo get_option('shoboto_maincolor'); ?>;"><p>'

Now when I save, the page goes blank. I'm entirely positive the style="background: ;" is correct, since it changes the color in logo of the site, the code for which is located in header.php. So I think it has something to do with the order of loading wordpress elements. Am I right? I mean the header (I think) loads after my options page passes the value, but functions.php loads earlier. Am I right? And if so, how can I tackle this problem? Any other ways you know to allow users to change colors?

  • 写回答

1条回答 默认 最新

  • dongyou8368 2013-09-30 02:49
    关注

    if you take a look at the line

       'before title' => '<div class="widget-header" style="background: <?php echo get_option('shoboto_maincolor'); ?>;"><p>'
    

    you'll notice that you have a <?php ?> inside the rest of your php code

    so the end result ends up looking something like

    <?php .... <?php ... ?> ... ?>
    

    this will output an error and since the debugging is turned of by default you'll get the white page as the document failed to parse...

    so you need to change that line to

    'before title' => '<div class="widget-header" style="background:' . get_option('shoboto_maincolor') . '"><p>',
    

    in order to get rid of the parsing error

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像