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

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

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集