Welcome Guest, Not a member yet? Register   Sign In
Codeigniter View in Wordpress Template
#1

[eluser]brainer[/eluser]
Hopefully someone can answer this...

I have a wordpress blog running beside a codeigniter app and I'm wondering if it is possible to include a codeigniter controller, which in turn loads a view.

my folder structure is

root
-system
-application
-blog (wordpress blog is here)

let say my controller is here:
http://mysite.com/blog_includes/header

can i do something like this in my wordpress template.

Code:
<?php include('http://mysite.com/blog_includes/header'); ?>

this doesnt work though i get an error

UPDATE: now using

Code:
<?php echo file_get_contents('http://mysite.com/blog_includes/header'); ?>

which loads the file but my session is not being maintained,
http://mysite.com/blog_includes/header should display the logged in users name
#2

[eluser]nmormino[/eluser]
Are you still having problems with this? I started an integration with wordpress and CI today and I think you could alleviate this problem if you were using relative urls with your includes. (that is if they are installed on the same server)

-Noah
#3

[eluser]123wesweat[/eluser]
how did you set op your .htaccess on root level and on blog level if i may asked

i thought i could by htaccess by using something like
Code:
$route['news'] = "blog";
$route['news/:any'] = "blog/$1";
but CI expects a controller so it gives me an page error.

So i think i must edit .htaccess on root level. how did you set your .htaccess??

Any other tips/tricks for CI + WP is highly appreciated Smile
#4

[eluser]nmormino[/eluser]
Yes I set up CI's .htaccess in the root directory, and WP's .htaccess in the blog directory. You don't need to use routes to handle wordpress. Since "blog" is an actual folder the system should look their on it's own.
#5

[eluser]123wesweat[/eluser]
@nmorimino, tx for your reply.

so the .htaccess in the blog can be used to SEO the WP posts, right??

Did you encounter problems when CI url's conflicts with WP url's or will /blog/ prevent this?
#6

[eluser]nmormino[/eluser]
I do not have a blog controller in CodeIgniter. I allow Wordpress to serve it's own content. I do make Wordpress use my CI templating for it's header & footer. by adding

require('blog/wp-blog-header.php');

to the top of my CI index.php, I have access to all the Wordpress templating functions from within CI.

-Noah
#7

[eluser]123wesweat[/eluser]
hi Noah,

Quote:to the top of my CI index.php, I have access to all the Wordpress templating functions from within CI.

that's exactly what i am doing.


Couple of questions:
In your setup you have created a WP theme which look like one of your CI view?

Quote:I do make Wordpress use my CI templating for it’s header & footer.
How did you do this??

Do you have WP permalinks in one of your CI views which links to ......?
Have you tried to create "blog" CI views with WP templating/functions? Should i made a seperarte controller for this??

At the moment if you click on a WP permalink it goes to /blog/?p=123 (will be permalinks) and shows a WP theme. I like to show a CI view with the content or would this lead to more problems then just making a WP theme looking like CI??

What i am trying to do:
1/ Have WP as a CMS for the blog/news part of my website
2/ Use some of WP plugins/functions in CI views
3/ Have CI blog views (for example summary and single view) so i have the frontend
in CI and not a WP theme



regards
#8

[eluser]nmormino[/eluser]
sorry can't answer all of your questions right now, sick baby.

but this is how I use CI templates in wordpress

include($_SERVER['DOCUMENT_ROOT'].'/sys/app/views/header.php');

I put that in my wordpress header.

I also let wordpress handle it's own views, by making wordpress use code igniters header and footer etc. the two systems look identical.

you can also put an htaccess file in the blog directory to make your urls pretty


making the themes match is incredibly easy using the methods I pointed out above. if you have some variables required in your CI theme that wordpress doesn't fulfill you can just set them above, or use output buffering to get whole chunks into a variable.

this is how my wordpress header file looks

Code:
<?php
ob_start();
wp_title('«', true, 'right').' '.bloginfo('name');
$page_title = ob_get_contents();
ob_end_clean();

ob_start(); ?>
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
<?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?>
<?php wp_head(); ?>
<?php
$header = ob_get_contents();
ob_end_clean();

function current_url()
{
    return 'http://'.$_SERVER['HTTP_HOST'].'/';
}
function base_url(){
    return 'http://'.$_SERVER['HTTP_HOST'].'/';
}
$path    = $_SERVER['DOCUMENT_ROOT'].'/sys/app/views/header.php';
include($path);
?>

much of the code in here converts what wordpress ordinarilly puts out, into what my CI theme requires. Then it includes the CI header and all works well.
-Noah
#9

[eluser]123wesweat[/eluser]
@nmormino,

hi again, hope everybody is well.

I encountered a major issue the sessions part doesn't work anymore. I am using DX_auth
and i think
Code:
function is_logged_in()
    {
        return $this->ci->session->userdata('DX_logged_in');
    }
returns false

if i don't have require_once './blog/wp-load.php';

the ci auth works again.

I really need the WP intergration as well. Do you know a solution???

ps: or should i put CI in a subfoler and WP in the root??
#10

[eluser]nmormino[/eluser]
you're wanting to integrate wp and CI authentication for admin as well?

I have not had a need for this yet so there has been no reason for me to investigate it. At first glance though, I think it would be a bad idea to use 2 different auth systems and try to make them play together. Seems to me you should do 2 things.

1. is it easier to replace wp users.
2. Is it easier to make CI look at WP sessions.

Since CI uses it's own sessions and not native sessions, using the sessions library will not allow you to access the wordpress session. You may want to look at moving CI to utilize native sessions first, then accessing WP's session information.

-Noah




Theme © iAndrew 2016 - Forum software by © MyBB