It has been almost twelve months since I published my first tutorial on embedding WordPress into OS Commerce. At the time, I was relatively new to working with OSC, so I was unaware of the many different template modules available for the software. Through the comments on my post, I learned that the OSC install that I was working with used the Basic Template Structure (BTS). However, people inquired about adjusting my tutorial for use with the Simple Template System (STS). Still more persons asked questions pertaining to default installs of OSC MS2.2.
Keeping all of these comments in mind, this month I put together a default install of OSC MS2.2 with an integrated WordPress blog. What follows is a step-by-step tutorial (with the novice in mind) showing you how to do this. For the many people who are looking for an effective way to integrate OS Commerce and WordPress, I hope this tutorial proves to be a valuable and effective contribution to the OSC Community.
- First, you will need to install OSC MS2.2 on your web server. This tutorial will assume that your OSC install is located in the default location for a typical OSC install: http://yourdomain.com/catalog/.
- Next, install WordPress in the /catalog/ directory (i.e. http://yourdomain.com/catalog/wordpress/). Once you’ve installed WordPress, login to your WordPress admin and set Options > General > Blog address (URI) to “http://yourdomain.com/catalog/blog.php” (Note: If you would prefer to have your blog file named something other than blog.php, be sure to set this value accordingly and rename the file that you upload in step 4).
- Now, just after the opening comments of the /catalog/includes/application_top.php file, add the following PHP code:
// turn off WordPress themes and include the WordPress core: define('WP_USE_THEMES', false); require('./wordpress/wp-blog-header.php'); - Next, download these two files (blog.php and stylesheet.blog.css) and place them in the root of your OSC install.
Additional Refinement: Displaying Blog Headlines on your Catalog Homepage
For added functionality, here are instructions for including a WordPress static page and blog headlines on the homepage of your OSC store:
- Before making this edit, you’ll want to make a backup of your default OSC homepage by renaming the file /catalog/index.php to index.ORIGINAL.php
- Now, download this new index.php file and upload it to your /catalog/ directory. This new index file will display your last 4 blog headlines in a column on the right of the page body. Plus, the value for TEXT_MAIN found in /catalog/includes/languages/english/index.php will display in the left column of the page body.
- In addition, starting on line 292 of this new index file, I have a switch inserted that will check for the presence of Vito Tardia’s Improved Include Page WordPress Plugin. If you install Vito’s plugin in WordPress, you can edit the iinclude_page() function call on line 294 to include the contents of any WordPress static page by simply editing the page ID in the function’s arguements.
Needing Additional Help?
If you’re a total novice when it comes to the web, you can hire me to perform the aforementioned services for you. At the demonstration website mentioned in this post, you can purchase one of these options:
When you disable the use of themes in the application_top.php, which files would you modify to change the way it is displayed, i.e., sidebar.php or something similar to that?? Does disabling themes force wordpress to use the default theme??
Thanks for your help!
I love the direction this is going, but I’m having a couple problems. Could you help me figure out how to get my sidebar to work work correctly? Also, my comments are not visible, they are posting but they aren’t showing up on my blog page… any ideas?
Hopefully you can help me, thanks!
@gautama – To get comments to display, add the following code:
< ?php comments_template(); ?>
Regarding the sidebar, I need to write a Part III to this tutorial that takes advantage of “widgetized” sidebars which are a part of the most recent versions of WordPress. When I wrote this tutorial two years ago, WordPress widgets were just coming onto the scene.
Your Demo isn’t working!!! I’d like to see how the wordpress integration looks like!
http://osc-wordpress.wh-demo.com/
@none – Thanks for noticing! Your comment made me realize that I needed to make a server-side adjustment due to a recent upgrade from PHP4 to PHP5.
Hi, I did the install, but when I finished I got this error on blog.php
Fatal error: Call to undefined function: get_bloginfo() in /home/northcen/public_html/blog.php on line 14
??
Just to let you know this is exactly what I want to do and would love to see that demo
everything is working, but when i update index.php with the one you provide, the last 4 blog headlines doesn’t display.
It’s empty… any idea how to fix that?
I followed the instructions, but it seems there’s no css at all for my blog anymore. Is there something I should check?
When I follow these instructions, the admin pages lose the css. I’d like it to retain it, since a non-css version is ugly and difficult to navigate. Did I miss something somewhere?
@EmmaK – Hmm…I’m unsure of what you could have done to drop the CSS from your admin. I’ve never heard of this before.
@n00b0101 – Check to see that stylesheet.css and stylesheet.blog.css are in the root folder of your OSC install.
Great contribution Michael. Thanks for sharing!
I had a problem though.
Because I was using OsCommerce STS template system, and Header Tags SEO contributions. The meta tags were all the same for all blog pages.
I have came up with a solution. Just add the code in the STS template file’s headers:
Basically this adds one header for the blog pages and the standard header for all other pages.
I hope this helps someone.
Cheers
Well, I’m just starting the whole thing from scratch, so maybe I mangled something at one point and this will solve it.
By the way, did hackers really hack the demo? I can’t get to it. :-/
Thanks for this plug-in Michael! I just did an integration found here: http://www.calsk8.com/skateshop/
Regarding the 404 errors and SEO problems… I ran into those as well. We run Ultimate SEO. Simple solution: turn off permalinks in wordpress. It appears that having mod-rewrite on both Oscommerce links and WordPress links doesn’t work out well. No idea why that is.
I put two dynamic sidebars within oscommerce boxes. We wanted the blog and pages accessible from everywhere. This eliminates a second “blog” sidebar (as your demo has).
In “column_right.php” i put:
require(DIR_WS_BOXES . ‘blog_sidebar.php’);
I created a “blog_sidebar.php” in includes/boxes/. I put the stuff below… your milage may vary. This worked… our oscommerce design is not highly modified so it should look fairly good for you:
We are having some problem displaying the blog RSS feed. In IE, it shows the following errors:
Only one top level element is allowed in an XML document.
Line: 64 Character: 2
We noticed that in the RSS html source just after , it shows session error and then immediately include the entire html of the page where RSS link is located:
Warning: session_start() [function.session-start]: Cannot send session cookie – headers already sent by (output started at C:\xampp\htdocs\st\blog\wp-includes\feed-rss2.php:12) in C:\xampp\htdocs\st\includes\functions\sessions.php on line 102
………………..
Any help will be much appreciated.
We are having some problem displaying the blog RSS feed. In IE, it shows the following errors:
Only one top level element is allowed in an XML document.
Line: 64 Character: 2
We noticed that in the RSS html source just after , it shows session error and then immediately include the entire html of the page where RSS link is located:
Warning: session_start() [function.session-start]: Cannot send session cookie – headers already sent by (output started at C:\xampp\htdocs\st\blog\wp-includes\feed-rss2.php:12) in C:\xampp\htdocs\st\includes\functions\sessions.php on line 102
………………..
Any help will be much appreciated.
Michael,
Thanks so much for this contribution – excellent work!
I’ve integrated the blog into my website and put the headline box in the body so people can link through to the blog, but I wondered if you could point me in the direction of placing the blog updates in the left column rather than the centre?
Keep up the good work!
B
I’m having the same problem as Basabi. Feed Validator produces an XML parsing error, ‘junk after document element’. Interestingly, the following links seem to work:
wordpress/wp-rss.php
wordpress/wp-rss2.php
wordpress/wp-commentsrss2.php
although I don’t know how to get my blog to link to these addresses instead of blog.php?feed=rss2 and blog.php?feed=comments-rss2. I’ve tried upgrading WordPress and deactivating plugins, to no avail.
Any help would be greatly appreciated.
Many thanks for all the effort you’ve put into this tutorial.
Hi Michael, great tutorial thanks. I have added links to this page in the OSC forum.
I hope you can help me customise my install…. I’m not getting any comments show up. Also, the categories are not showing up on the right….
http://www.boomclothing.com/store2/mobbblog.php
PLEASE HELP – I really need to get this running asap!!
@Sol – Here’s a possible solution for getting your comments to show up based on what I’m seeing over at the WordPress Codex. In blog.php, on the line just before the call to comments_template(), add the following:
<?php $withcomments = 1; ?>To get the categories to show up, in blog.php, replace the call to wp_list_cats() with wp_list_categories().
wp_list_cats() is deprecated. This tutorial is starting to show its age. Perhaps another update is in order this fall? We’ll see.
Re: my earlier problem
In case anyone else has the same problem, you can add a different feed link (eg. wp-rss.php) to blog.php before . I also deleted the meta links section to get rid of the original, broken feed link.
before
<!-- end sidebar -->Hi Michael
Thank you for your suggestion, unfortunately, this didn’t solve it.
I’m pretty desperate to get this sorted as I’ve people waiting to write their blogs!!
For anyone who is interested, the blog is here:
http://www.boomclothing.com/store2/mobbblog.php
The problem is: the comments aren’t showing up and the categories don’t display on the right.
I would be happy to pay someone to help sort this out
Please contact me via the website.
Regards
Sol
Hi Michael,
This is great. Thanks a lot for this guide! I dont no what i’d have done without it.
I am encountering the same problem as Sol, – categories, pages and comments are not visible.
If i turn on templates, they are visible again, but then the Oscommerce freaks out and says “Cannot send session cache limiter – headers already sent “.
Please help me out with this thing, it would mean a lot to both me and Sol I’ll guess.
Anyhow, many thanks to you for doing this for the Oscommerce community!
Take care! / J
Hey Michael, thanks for the awesome contribution. However, I’m having a bit of difficulty. I’ve been searching everywhere, haven’t found a satisfactory solution and am at the end of the line so I’m hoping you can help me. I successfully installed the blog on my site, but when I click on an individual post, it opens into a new page without the rest of the store. I’d really like each post to stay within the site, how should I fix this? My blog is at lovethelimelight.com/blog.php
@Lindsay – /blog/?p=75? = /blog.php?p=75
In the end I paid a programmer to get mine working… even then, he told me there are lots of issues with merging the two….
Hi Michael. Thanks for the great contribution. You saved my time for hours. Eventhoug your contrib looks nice and fitted to osC but i prefer to put it into either column_right or column_left. Could you help me? Thanks a lot. here is my web:
http://senyumuslim.com
i mean the headlines box should be in column left/column right
Hello, i have a problem. This hack works in my localhost but when I upload to my hosting (totalchoicehosting) WP_Query returns an array but empty
i’m trying to run a query with the loop, such as , but just shows up blank…anyone?
query_posts(‘cat=3′)
Hey!
Thank you so much for a fantastic contribution!
I have tried embeding Blogger blogs, costom OSC blog and so many other options, but have never reached so far as i have with thsi one, and just in 1/10 of the time!!
My only problem is that i run a danish OSC..
and after i managed to embed this “contribution” all my danish charactrs show as “?”
Do you have any idea on what i need to adjust?
Thank you in advance..
for those who have problems with the sidebars in php that wont display
just put the code at the bottom part of the application_top.php
// turn off WordPress themes and include the WordPress core:
define(‘WP_USE_THEMES’, false);
require(‘./wordpress/wp-blog-header.php’);
and it works fine
@Sol,
Do you know what your programmer did to get the categories to display in the sidebar? I’m having the same issue!
Thanks,
V
Hi,
I have a number of existing osCommerce sites that I’ve been trying to add WordPress to. With your blog.php file I now have the first page working on my site http://www.dandelionwebdesign.com/blog.php but the post links all go to the folder blog and are using a theme. What am I missing here?
@Ruth Maude: Without being able to “look under the hood,” my first place to look might be under “General Settings > Blog Address (URL)” to see if you set that to properly match where your blog should appear.
Hi all
I eventually paid a programmer to install it for me. It cost about NZ$250
I have studied the code he has written and I can tell you it is VERY messy! Not because he is a poor programmer, but because the OSC site is very difficult to integrate WordPress into.
So far, I have everything working – however, unfortunately there is no sidebar – my programmer tried several times to get the sidebar to work, but no good!
I would love to know if anyone has solved this because without a sidebar, I miss out on all the widgets (such as RSS feeds etc!)
If anyone wants further help, feel free to contact me and I will try my best – though I suggest paying someine to do the job for you – it will save you a week of headaches!
Hello,
I hope you dont mind but I updated some of these files for my website so i posted them on the add-ons part of the oscommerse site
here it is: http://addons.oscommerce.com/info/6809
have a look at my site for how it works:
http://test.thevitalitystore.com.au/blog.php
@Technoicon
Hey, your blog looks good and it was a great idea to post it on the osc contributions page.
Did you use some of the code from my website? Just curious!
Hi Michael,
Your tutorial was the answer to my tech prayers. I’m unfortunately in the same boat as Dale with the following error:
Fatal error: Call to undefined function: get_bloginfo() in /home/content/s/c/o/scourge/html/shop/blog.php on line 14
Do you have any thoughts on what might be causing this?
I’m hosting on godaddy.com, using WordPress 2.7, and OSC 2.2
Many thanks
I have a problem with my links, they look
http://www.example.com/blog.php/?p=1&cpage=1#comment-1
attention here
/blog.php/?
I realize that this form is like they will must look my links but not working, I followed all step , may be the error is because I installed oscommerce over root directory, help me please
I’m getting errors trying this…
Warning: require(./wordpress/wp-blog-header.php) [function.require]: failed to open stream: No such file or directory in /home/site/public_html/shop/includes/application_top.php on line 15
any ideas as to why?
Fantastic information on how to merge wordpress and osCommerce and works a treat. Thank you so much for taking the time to put this out there. It was easy, and worked first time, great stuff.
I only used what you had here to download. and the information from this blog. i added a link to this blog for you in the contrib.
I will start a forum post to allow questions and i will help were i can.
let me know if you want to add more info about you making this contrib ect.
i basically just edited it a little so that the custom widgets worked using my theme, this needs to be automated a little better and stuff.
hi, i have made a forum thread now here,
so go check it out:
http://forums.oscommerce.com/index.php?showtopic=339690
@technoicon: Great idea. Thanks for creating that forum post.
The whole idea of combining WordPress and OSC is one which requires the skills of both the artist and the programmer. Hopefully, the thread you started will be a place where people can build upon what I’ve started here.
Thanks for this awesome contribution.
I was having this problem with the install and for anyone having problems with blog.php/?p=1. You have to change the permalink in wordpress by going to wordpress admin page>settings>permalinks, then use one of the other structure instead of default. The default permalink structure uses “/?” which causes issues with osC’s linking structure.
Another issue I came across was…
Fatal error: Call to undefined function: get_bloginfo() in /something/something/blog.php on line 14
To fix this, I had to use the following in applicaton_top.php instead of the one provided in the instruction.
// turn off WordPress themes and include the WordPress core:
define(‘WP_USE_THEMES’, false);
require(‘your_wordpress_folder/wp-blog-header.php’);
Notice that there are no “../wordpress”
Hope the above helps someone with their install.
An issue I’m having now is integrating this with STS templates and getting rid of the right column. I made a blog.php.html file which works fine when you go to mysite.com/blog.php. If I click on any link inside the blog then it will bring me to a link that is blog.php/year/month/id for which STS template couldn’t tell belongs to blog.php and thus uses the default template. My default template already have a right column set up so it will display two right columns making things ugly. Could anyone please point me in the right direction to make STS template know that blog.php/yr/mo/id should use the blog.php.html. Thank you.
If anyone is still battling with RSS feed problem, here is one possible solution.
Problem: If you use RSS feed option after integrating oscommerce, you might see some error messages regarding session. Firefox is more forgiving so may actually work but IE will just fail.
Root cause:When you use RSS feed, the code in the blog.php gets appended to the XML file that is generated by the standard wordpress stuff.
Solution: Once solution is forcing PHP to exit once it creates the XML file that is needed for RSS feed. If the PHP doesn’t exit at this point, the PHP script will continue and add all the unnecessary code from blog.php. Here is what you can do.
Open the wp-includes/template-loader.php . This file has a big if-else block. In the else block, find this code
..
else if (is_feed()) {
do_feed();
}
At the end of do_feed(), add exit(0) and this should fix the problem.
My guess is that needs to be done for other conditions too. May be a better solution would be adding an exit(0) at the end of the big else block but I’ve not tested it.