2016-04-25 205 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