繁体   English   中英

WordPress自定义主题,PHP问题

[英]WordPress custom theme, PHP issue

我最近将WordPress网站以及所有插件和主题更新到当前版本。 更新之后,我的getsidebar()出现了问题;

我的sidebar.php具有以下代码:

<?php if ($cfs->get('sidebar_recent-event_text') || $cfs->get('sidebar_recent-event_number')) { ?>
    <div class="recent-event-call pie-rounded">
       <p><?php echo $cfs->get('sidebar_recent-event_text');  ?></p>
       <p class="phone-number"><?php echo $cfs->get('sidebar_recent-event_number');  ?></p>
    </div>
<?php } ?>

<?php if ($cfs->get('sidebar_covered_text')) { ?>
    <div class="what-is-covered pie-rounded">
        <h4><?php echo $cfs->get('sidebar_covered_header');  ?></h4>
        <?php echo $cfs->get('sidebar_covered_text');  ?>
    </div>
<?php } ?>

<?php if ($cfs->get('sidebar_covered_text_mobile')) { ?>
      <div class="what-is-covered what-is-covered-mobile pie-rounded">
        <h4><?php echo $cfs->get('sidebar_covered_header_mobile');  ?></h4>
        <?php echo $cfs->get('sidebar_covered_text_mobile');  ?>
     </div>
<?php } ?>

<?php if ($cfs->get('sidebar_questions_text')) { ?>
   <div class="questions pie-rounded">
       <button class="questions-link-button" onclick="location.href='mailto:<?php echo $cfs->get('sidebar_questions_link');  ?>'"></button>
       <h4><?php echo $cfs->get('sidebar_questions_header');  ?></h4>
       <?php echo $cfs->get('sidebar_questions_text');  ?>
   </div>
<?php } ?>

在我的模板文件中

<?php get_sidebar(); ?>

我收到错误提示:注意:未定义的变量:第1行的sidebar.php中的cfs

如果我仅使用一些简单的html删除了php文件中的代码,例如

<div><b>test test test test</b></div>

然后加载就好了。

如果我从sidebar.php文件中复制php代码并将其直接粘贴到模板文件中,那么它也可以很好地加载。 因此出于某种原因,sidebar.php中的php无法运行。 不知道如何解决。
我不是PHP开发人员,所以我不知道为什么PHP无法加载。 你能帮我么。

您的侧边栏由于指定的错误而未加载:

 Notice: Undefined variable: cfs in sidebar.php on line 1

通过将以下行添加到您的.htaccess文件中,您可能能够获得有关该错误的更多信息:

php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
php_flag  log_errors on
php_value error_log  /home/path/public_html/domain/PHP_errors.log

$ cfs可以是任何内容-但我之前在Custom Field Suite插件中已经看到过使用此变量。 如果未安装并激活此插件,则可能需要尝试一下,以查看侧边栏是否正常运行。

如果这引用了Custom Field Suite插件,那么将其设置为sidebar.php顶部的global是否有帮助?

<?php global $cfs; ?>

这将允许您访问

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM