Welcome Guest, Not a member yet? Register   Sign In
[solved] CI / WP integration woes
#1

[eluser]CroNiX[/eluser]
So on this current project, we have built a site around and existing wordpress blog. Wordpress will still be used for the blog portion and is installed in /blog. On my CI homepage controller, I need to pull some recent articles from the blog, so I instantiated the wp from within my ci index.php as the first line.

Code:
if($_SERVER['REQUEST_URI'] == '/')
{
    require('blog/wp-blog-header.php');
}
I only want to instantiate it if its on the homepage as thats the only place it will be used.

This works fine, now I can use wp commands to get posts, etc. from wp.

The problem happens from any link generated using CI (anchor() command) on that page now. It works fine without instantiating WP, but when it does all links generated by ci is now prefixed by /blog/whatever.

So if the link is supposed to be www.mysite.com/help it now shows up as www.mysite.com/blog/help. This using:
Code:
anchor('help', 'Help Page');

Does anyone know what can be causing this and if there is a solution? Everything else works just great except this one thing which is perplexing me. Why would having the wp object instantiated cause CI to mess up urls?

Thanks,
CroNiX
#2

[eluser]skunkbad[/eluser]
I've never tried this CI WP integration, but it sounds like you need to build your links using base_url().
#3

[eluser]CroNiX[/eluser]
Yes, the problem turned out that WP also has a site_url() function, and since WP was getting instantiated before CI, the CI function wont load because its already defined.

To fix this I just created a new helper with a function called make_anchor() that was a clone of the CI anchor() function but had it use base_url() to generate the links instead of site_url().

Thankfully it is only on the home page that the WP integration occurs or I would have to change an awful lot of views.




Theme © iAndrew 2016 - Forum software by © MyBB