2017-08-30 113 views
0

我的一个Wordpress主题是显示以下错误:WordPress的主题致命错误“致命错误:调用未定义的方法WP_Error :: get_items()”

Fatal error: Call to undefined method WP_Error::get_items() in /home1/mywebsite/public_html/learnphp123.com/wp-content/themes/econews/admin/IDE_admin.php on line 88 

该文件的代码(你可以看到上线88“get_items()” ......居然在第三行代码):

if($feed) { 
       $html = '<ul>'; 
       foreach ($feed->get_items() as $item){ 
        $html.="<li><span>".$item->get_date('d M Y')."</span> <a href=\"".$item->get_permalink()."\">".$item->get_title()."</a></li>"; 
       }  

谁能告诉我在"get_items()"的地方使用什么?

非常感谢您的帮助! 该文件的总代码如下,我只收到第88行有关feed get_items()的错误。

<?php 

/* 
    Copyright 2010, idesigneco.com 
    http://idesigneco.com 
*/ 

define('IDE_ADMIN_FEED', 'http://idesigneco.com/wp_pub.php?id=ide_admin_newsfeed.xml&theme='.IDE_CODE.'&ver='.IDE_VERSION); 

// load form generator and validator 
include IDE_ADMIN_PATH.'IDE_FormGenerator.class.php'; 

// initialize the admin form 
$Form = new IDE_FormGenerator(array(
    'name' => 'admin', 
    'method' => 'post', 
    'action' => '' 
)); 

// setup the form fields 
$Form->elements(
    null, 
    array(
     'admin_action' => array(
      'type' => 'hidden', 'value' => 'admin', 
      'error' => 'Your settings have been updated.' 
     ) 
    ) 
); 

// load theme specific options 
include IDE_ADMIN_PATH.'/IDE_admin_options.php'; 

$Form->elements(
    null, 
    array(
     'submit' => array(
      'type' => 'submit', 'value' => 'Save', 'label' => '' 
     ), 
    ) 
); 

$Form->printErrors(true); 


// ________________________________________________________ 

// process the form data 
if(!empty($_POST['admin_action'])) { 

    // unchecked checkbox options don't show up, so fill them with predefined key names 
    ide_save_options(array_merge(array_fill_keys($IDE_checkboxes, ''), 
            stripslashes_deep($_POST) 
           ) 
        ); 
    $Form->setErrors(array('admin_action')); 
} 

// ________________________________________________________ 

// populate the form with saved options 
$Form->data($IDE_options); 

// ________________________________________________________ 


// print out the admin area 
ide_admin_header(); 
$Form->generate(); 
ide_admin_footer(); 

// ________________________________________________________ 

// idesigneco news feed 
function ide_admin_news() { 

    $time = ide_option('admin_newsfeed_time'); 
    $html = ide_option('admin_newsfeed'); 


    // feed expired, update 
    if(!$html || !$time || ($time+(5*3600)) < time()) { 
     if(function_exists('fetch_feed')){ 
      $feed = fetch_feed(IDE_ADMIN_FEED); 

      if($feed) { 
       $html = '<ul>'; 
       foreach ($feed->get_items() as $item){ 
        $html.="<li><span>".$item->get_date('d M Y')."</span> <a href=\"".$item->get_permalink()."\">".$item->get_title()."</a></li>"; 
       } 
       $html.= '</ul>'; 
      } else { 
       $html = 'Updates unavailable at this time'; 
      } 
     } else { 
      // deprecated feed api 
      if(function_exists('fetch_rss')){ 
       include_once(ABSPATH . WPINC . '/rss.php'); 
       $rss = fetch_rss(IDE_ADMIN_FEED); 
       $html = '<ul>'; 
       foreach ($rss->items as $item){ 
        $html.="<li><span>".date('d M Y', strtotime($item['pubdate']))."</span> <a href=\"".$item['link']."\">".$item['title']."</a></li>"; 
       } 
       $html.= '</ul>'; 
      } 
     } 

     ide_save_option('admin_newsfeed_time', time()); 
     ide_save_option('admin_newsfeed', $html); 
    } 


    echo $html; 
} 


// admin header 
function ide_admin_header() { 
    ?> 
    <div id="ide_admin"> 
     <div class="left"> 
     <h1 class="ide_title"><?php echo IDE_NAME.' '.IDE_VERSION; ?></h1> 
     <div class="clear"> </div> 
    <?php 
} 

// admin footer 
function ide_admin_footer() { 
    ?> 
     </div><!-- left //--> 

     <div class="right"> 
      <div class="idesigneco"> 
       <a href="http://idesigneco.com"><img src="<?php echo IDE_ADMIN_STATIC.'/idesigneco.png'; ?>" alt="Theme by iDesignEco" title="Theme by iDesignEco" /></a> 
      </div> 
      <div class="news"> 
       <h2>iDesignEco Updates</h2> 
       <?php ide_admin_news(); ?> 
      </div> 
     </div><!-- right //--> 
     <div class="clear"> </div> 

    </div><!-- ide_admin //--> 
    <?php 
} 

?>

+0

究竟是什么$喂一个实例?不知道我们不知道该对象上有哪些方法可用,并且您收到的错误显示$ feed对象中不存在get_items()方法。 – flauntster

+0

不知道函数'get_items()'做了什么,它不可能告诉替换该函数。 – tousif

回答

0

这可能发生在为$feed获取数据失败,所以它成为不具备get_items()方法WP_Error类。试图修改这样的代码:

if (! is_wp_error($feed)) { 
      $html = '<ul>'; 
      foreach ($feed->get_items() as $item){ 
       $html.="<li><span>".$item->get_date('d M Y')."</span> <a href=\"".$item->get_permalink()."\">".$item->get_title()."</a></li>"; 
      } 

UPDATE:

正如我认为,在$feedfetch_feed()获取数据,因此该解决方案仍应该更换:

if($feed) { 

附:

if (! is_wp_error($feed)) { 
+0

因为get_items()方法不存在,if中的部分将永远不会执行。它与要求完全删除导致错误的那部分代码相同。 – tousif

+0

你好,主题的饲料总代码如下 – Mansan

+0

我修改了答案。我使用https://codex.wordpress.org/Function_Reference/fetch_feed的支票 – user8230352

相关问题