• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[solved] CI / WP integration woes

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.

if($_SERVER['REQUEST_URI'] == '/')
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:
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?


I've never tried this CI WP integration, but it sounds like you need to build your links using base_url().

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.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.