Embedding WordPress into OS Commerce Part II

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.

osc_wordpress.jpgKeeping 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.

  1. 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/.
  2. 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).
  3. 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');
  4. 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:

  1. 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
  2. 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.
  3. 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:

Categorized: Tutorials

97 Comments

  • Jan 26, 2008 - 12:56 am

    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!

  • Jan 27, 2008 - 8:47 am

    @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.

  • noneReply to this comment
    Feb 12, 2008 - 2:52 pm

    Your Demo isn’t working!!! I’d like to see how the wordpress integration looks like!
    http://osc-wordpress.wh-demo.com/

  • Feb 12, 2008 - 3:03 pm

    @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.

  • Feb 29, 2008 - 5:06 pm

    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

    ?? :(

  • Apr 7, 2008 - 1:03 pm

    Just to let you know this is exactly what I want to do and would love to see that demo ;)

  • momotaReply to this comment
    Jun 9, 2008 - 2:46 pm

    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?

  • n00b0101Reply to this comment
    Jun 19, 2008 - 11:42 am

    I followed the instructions, but it seems there’s no css at all for my blog anymore. Is there something I should check?

  • EmmaKReply to this comment
    Jun 19, 2008 - 11:53 am

    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?

  • Jun 19, 2008 - 2:33 pm

    @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.

  • TinoReply to this comment
    Jun 19, 2008 - 2:34 pm

    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:

    
    <?php
    if (preg_match("/(.*)blog.php(.*)/", $_SERVER['REQUEST_URI'])) {
    	echo "<title>";
    	wp_title('');
    	if(wp_title('', false)) { echo ' :'; }
    	bloginfo('name');
    	echo "</title>";
    	wp_head();
    	wp_get_archives('type=monthly&format=link');
    	echo '<link rel="pingback" href="' .get_bloginfo('pingback_url'). '" />';
    	echo '<base href="http://www.YOURSITE.com" />';
    } else {
    	echo '<!--' .$headcontent. '-->';
    }
    ?>
    

    Basically this adds one header for the blog pages and the standard header for all other pages.

    I hope this helps someone. ;-)

    Cheers

  • EmmaKReply to this comment
    Jun 19, 2008 - 4:12 pm

    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. :-/

  • Jun 26, 2008 - 11:58 am

    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:

    
    <?php
    /* Blog Sidebar by Paul Ireland for Cal Skate Skateboards (http://www.calsk8.com/) 6/26/2008 */
    ?>
    <!-- blog sidebar //-->
    <tr><td>
    <?php
      $info_box_contents = array();
      $info_box_contents[] = array('text' => "Blog Stuff");
    
      new infoBoxHeading($info_box_contents, false, false);
    ?>
    <table border="0" width="100%" cellspacing="0" cellpadding="1" class="infoBox">
      <tr><td><table border="0" width="100%" cellspacing="0" cellpadding="3" class="infoBoxContents">
      <tr><td><img src="images/pixel_trans.gif" width="100%" height="1" border="0" alt="  "></td></tr>
      <tr><td align="left" class="boxText"><div id="blog_sidebar"><ul><?php  dynamic_sidebar('Main Sidebar'); ?></ul></div></td>
      </tr><tr><td><img src="images/pixel_trans.gif" width="100%" height="1" border="0" alt="  "></td></tr></table></td></tr></table></td></tr></td></tr>
    <!-- blog_sidebar_eof //-->
    
  • basabiReply to this comment
    Jul 26, 2008 - 4:56 am

    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.

  • BasabiReply to this comment
    Jul 28, 2008 - 12:59 am

    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.

  • Aug 9, 2008 - 10:51 am

    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

  • Aug 31, 2008 - 8:22 pm

    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.

  • SolReply to this comment
    Sep 3, 2008 - 7:31 pm

    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!!

  • Sep 3, 2008 - 8:01 pm

    @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.

  • Sep 12, 2008 - 9:12 pm

    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.

  • Sep 12, 2008 - 9:25 pm

    before <!-- end sidebar -->

  • SolReply to this comment
    Sep 12, 2008 - 11:30 pm

    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

  • JayReply to this comment
    Oct 7, 2008 - 11:32 am

    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

  • Oct 11, 2008 - 8:23 am

    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

  • RyanReply to this comment
    Oct 30, 2008 - 12:02 am

    @Lindsay - /blog/?p=75? = /blog.php?p=75

  • SolReply to this comment
    Oct 31, 2008 - 6:46 am

    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….

  • Nov 10, 2008 - 1:33 am

    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

  • Nov 10, 2008 - 1:35 am

    i mean the headlines box should be in column left/column right

  • FranReply to this comment
    Nov 16, 2008 - 8:57 pm

    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

  • paulieReply to this comment
    Nov 21, 2008 - 6:20 pm

    i’m trying to run a query with the loop, such as , but just shows up blank…anyone?

  • paulieReply to this comment
    Nov 21, 2008 - 6:20 pm

    query_posts(’cat=3′)

  • Mar 10, 2009 - 9:25 am

    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..

  • jerryReply to this comment
    Apr 22, 2009 - 9:50 am

    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

  • VinnyReply to this comment
    May 7, 2009 - 5:47 pm

    @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

  • May 11, 2009 - 12:59 pm

    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?

  • May 11, 2009 - 1:10 pm

    @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.

  • SolReply to this comment
    Jun 7, 2009 - 6:12 am

    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!

  • Jun 11, 2009 - 4:12 am

    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

  • solReply to this comment
    Jun 11, 2009 - 5:26 pm

    @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!

  • DanielReply to this comment
    Jun 14, 2009 - 8:51 am

    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

  • eddoReply to this comment
    Jun 15, 2009 - 12:07 pm

    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/?

  • eddoReply to this comment
    Jun 16, 2009 - 9:36 am

    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

  • ChrisReply to this comment
    Jun 24, 2009 - 7:49 pm

    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?

  • Jun 30, 2009 - 2:37 am

    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.

  • Jun 30, 2009 - 4:08 am

    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.

  • Jun 30, 2009 - 4:24 am

    hi, i have made a forum thread now here,
    so go check it out:
    http://forums.oscommerce.com/index.php?showtopic=339690

  • Jun 30, 2009 - 8:51 am

    @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.

Post a Comment

Your email is never shared. Required fields are marked *

*
*