我已经在根目录下安装了wordpress,并在子目录下安装了codeigniter,一切都很正常。我可以给CI调度员打电话。然而,我也想使用相同的wordpress主题。例如:get_header(),get_sidebar()和get_footer()。
一个示例用法是传入我的codeigniter页面标题,以便wordpress在访问我的codeigniter端时不会显示Page not found标题。我有以下代码:
配置项控制器:
public function index(){
$data['ci_title'] = 'some title';
$this->load->view('header', $data);
}配置项视图(header.php):
<?php get_header(); ?>;
Wordpress主题文件(header.php):
<title>
<?php
if($ci_title) echo $ci_title else wp_title('');
?>
</title>现在问题是我的$ci_title没有在wordpress主题文件中被读取。我甚至尝试将globlal $ci_title放在get_header()函数中,但它再次调用了一些load_template()函数。
有没有简单的方法将配置项变量传递给wordpress主题文件?
发布于 2013-01-22 15:21:00
你并不需要去修改核心文件。您需要做的只是在header.php中添加以下代码行
$CI = &get_instance();
echo $CI->load->get_var('ci_title');您将获得在CI的装载器对象中传递的所有变量。
发布于 2012-05-01 04:47:25
好的,在经历了很多并最终阅读了http://www.php.net/manual/en/language.variables.scope.php#98811之后,我发现我需要在调用get_header()之前将我的$ci_title声明为global。现在,我的代码如下所示:
CI视图文件(header.php):
global $ci_title;
get_header();general-template.php中的WP函数wp_title()
function wp_title($sep = '»', $display = true, $seplocation = '', $ci_title = '') {
global $wpdb, $wp_locale, $ci_title;
//existing code.. and at the end
if($ci_title != ''){
$title = $ci_title;我不知道这是否是正确的方式,因为我只是一个PHP初学者,但现在它可以满足我的目的。但是,如果有更好的方法,让我避免修改wordpress函数,那就更好了。
https://stackoverflow.com/questions/10388607
复制相似问题