2016-04-25 171 views
1

我的笨工作不能重新声明SITE_URL,我想取就我的网页致命错误:()

网站主页的博客文章当我包括两个文件

require_once('blog/wp-blog-header.php'); 
require_once('blog/wp-includes/link-template.php'); 

我得到了一个错误。

function site_url($path = '', $scheme = null) { 
    return get_site_url(null, $path, $scheme); 
} 

这个错误被删除,网站wotks的所有功能,但是当我打开 博客是不开放它给错误

Fatal error: Cannot redeclare site_url() (previously declared in /home/homebidpro/public_html/dev/system/helpers/url_helper.php:83) in /home/homebidpro/public_html/dev/blog/wp-includes/link-template.php on line 3004 

我根据位置文件中所注释此功能dev.homebidpro.com页面无法正常工作

博客和项目位置i同样都在开发文件夹。

我坚持到现在。请尽快提供解决方案。

的代码的其余部分是

public function blogData() 
    { 

     require_once('blog/wp-blog-header.php'); 
     require_once('blog/wp-includes/link-template.php'); 

     if($catagory !='') 
     { 

      $args = array( 'posts_per_page' => 3, 'category_name' => $catagory); 
     } 
     else 
     { 

      $args = array('posts_per_page' => 4); 
     }  

     $mypostsMov = get_posts($args); 
     // echo "<pre>"; print_r($mypostsMov); die; 
     $mypostsarrayMov = array(); 
     $i=0; 
     foreach ($mypostsMov as $post) : 
     $excerpt = preg_replace("/<img[^>]+\>/i", "", $post->post_content);  
     $mypostsarrayMov[$i]['post_title'] = strip_tags($post->post_title); 
     $mypostsarrayMov[$i]['content'] = strip_tags($post->post_content); 
     $mypostsarrayMov[$i]['permalink'] = get_permalink($post->ID); 
     $mypostsarrayMov[$i]['thumbnail'] =get_the_post_thumbnail($post->ID,array(300, 200)); 
     $i++; 
     endforeach; 
     wp_reset_postdata(); 

     //echo "<pre>"; print_r($mypostsarrayMov); die; 

     //return $this->render('MovePlusServiceBundle:Default:recentpostCombined.html.twig',array('mypostsMov'=>$mypostsarrayMov,)); 

     return $mypostsarrayMov; 

} 

而且site_url功能,该功能在codeigniter

if (! function_exists('site_url')) 

{ 

    function site_url($uri = '') 
    { 
     $CI =& get_instance(); 
     return $CI->config->site_url($uri); 
    } 

} 

和SITEURL函数,它是博客的文件夹,我已经给你。

+0

您尝试重写一个组合的形式存在功能'SITE_URL()'你需要重命名功能或用户存在'SITE_URL()'或'get_site_url直接将网站的网址(null,$ path,$ cheme)'last是连击方式,因为为php调用函数这个功能太难了,太复杂了(difficalty我不知道如何改正写)你的应用程序。 – Naumov

+0

您只能定义一次函数'site_url()'。这个错误意味着它已经被宣布了一些其他的东西。 – Peter

+0

@peter:当我在site_url()函数中注释一个site_url()时,在这种情况下做什么,然后某些功能不起作用 –

回答

1

你的问题是,CI有在url helper一个site_url()功能,和WordPress也有一个功能site_url()这是wp-includes/link-template.php file中定义。

因为你已经在你的CodeIniter页面中包含了link-template.php,PHP告诉你你正试图创建一个已经存在的函数,而你不能这么做。

从我能想到的,你需要:

  • 无法加载你包括WordPress在页面上的URL CodeIgniter的帮手,或
  • 不能加载WP-包括/链接-template.php文件,或者加载CodeIgniter url帮助程序,或者将wp-includes/link-template.php文件中需要的功能复制到自定义库/帮助程序或控制器中,以便生成结果这需要包含文件。

你可能会选择实现这些

+0

请告诉我如何排除我不知道的CodeIgniter URL助手文件。因为我不知道codeigniter的合适结构 –

+0

有几种不同的管理方式,但这取决于你想要达到什么以及你实际需要什么。你是否需要wordpress的link-template.php的功能,如果是的话,你需要加载CodeIgniter的URL助手吗?同样,如果你只显示最近发布的帖子,你是否可以不使用RSS feed或使用wordpress API(不确定它是否允许,我没看过) – gabe3886