简体   繁体   中英

WordPress custom theme, PHP issue

I recently updated my WordPress site and all my plugins and themes to the current version. After the update I am having an issue with the getsidebar();

I have my sidebar.php with the following code:

<?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 } ?>

In my template file, I have

<?php get_sidebar(); ?>

I am getting and error that says: Notice: Undefined variable: cfs in sidebar.php on line 1

If I removed the code that is in the php file with just some simple html, like

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

Then it loads just fine.

If I copy the php code from the sidebar.php file and paste it directly into the template file then it loads fine too. So for some reason the php in the sidebar.php is not running. Not sure how to troubleshoot.
I am not a PHP dev so I don't know why the PHP is not loading. Can you please help me.

Your sidebar is not loading because of the error it specifies:

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

You may be able to obtain more information on the error by adding the following lines to your .htaccess file:

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 could be anything -- but I have seen this variable used before in the Custom Field Suite Plugin . If this plugin is not installed and activated, you may want to try that and see if your sidebar works properly.

If this is referencing the the Custom Field Suite plugin, might it help to put make it a global at the top of sidebar.php?

<?php global $cfs; ?>

This will allow you to access

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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