Embedding WordPress into OS Commerce

I’ve created the following tutorial in response to topic 47148: osCommerce and WordPress at WordPress Support.

While I have been programming PHP for a while, I am new to both OS Commerce and WordPress. That being said, for this integration I have tried to follow the coding standards for creating a new OS Commerce page. If you see any refinements I need to make to my code, feel free to comment. I hope this helps all of you who are looking to integrate OS Commerce and WordPress.

10/06/2006 – UPDATE: In response to comments below, I’ve written a Part II to this tutorial showing how to embed WordPress into a default install of OSC MS2.2.

PLEASE NOTE: The code in this tutorial assumes that your OS Commerce install is located in your server’s web root and your WordPress install is located in a subdirectory named wordpress/.

ALSO NOTE: This tutorial is written for OS Commerce installs using the Basic Template Structure (BTS). For OSC installs using the Simple Template Structure (STS), please see comment number 9 below:

  1. Create a file for your WordPress blog in the root folder of your OS Commerce install. For our purposes, we’ll name this file blog.php. The contents of this file are as follows:
    <?php
    /*
    Title: Embedding WordPress into OS Commerce
    Author: Michael Wender (www.michaelwender.com)
    Disclaimer: This Software is provided "AS IS" and without warranty of any kind. The user assumes all risks associated with its use and installation.
    $Id: blog.php,v 1.1.1.1 2004/03/04 23:38:02 ccwjr Exp $
    
    osCommerce, Open Source E-Commerce Solutions
    
    http://www.oscommerce.com
    
    Copyright (c) 2003 osCommerce
    Released under the GNU General Public License
    */
    
    // turn off WordPress themes and include the WordPress</b> core:
    define('WP_USE_THEMES', false);
    require('./wordpress/wp-blog-header.php');
    
    require('includes/application_top.php');
    require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_BLOG);
    $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_BLOG));
    $content = CONTENT_BLOG;
    require(DIR_WS_TEMPLATES . TEMPLATE_NAME . '/' . TEMPLATENAME_BLOG_PAGE);
    require(DIR_WS_INCLUDES . 'application_bottom.php');
    ?>
    
  2. Open the file oscommerce_root/includes/filenames.php.
    • Find the section that begins with the comment // define the content used in the project, and add the following code:
    • define('CONTENT_BLOG', 'blog');
    • Find the section that begins with // define the filenames used in the project, and add the following:
    • define('FILENAME_BLOG', CONTENT_BLOG . '.php');
    • Find the section that begins with // define the templatenames used in the project, and add the following:
    • define('TEMPLATENAME_BLOG_PAGE', 'blog_page.tpl.php');
  3. Create the following file: oscommerce_root/templates/your_template_dir/blog_page.tpl.php (Note: This file’s filename matches the variable you defined as TEMPLATENAME_BLOG_PAGE in filenames.php).

    The contents of this file will vary according to which template you are using (to start, I suggest making a copy of your main_page.tpl.php); however, the body content on this page will be your WordPress blog. You will display your blog using The WordPress Loop. The following file is only meant to show you how to get started. Your blog_page.tpl.php will vary according to the template you are using in OS Commerce:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html <?php echo HTML_PARAMS; ?>>
    <head>
    <meta http-equiv="Content-Type" content="text/html;
    charset=<?php echo CHARSET; ?>">
    <?php
    if ( file_exists(DIR_WS_INCLUDES . 'header_tags.php') ) {
      require(DIR_WS_INCLUDES . 'header_tags.php');
    } else {
    ?>
      <title><?php echo TITLE ?></title>
    <?php
    }
    ?>
    <base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
    <link rel="stylesheet" type="text/css" href="<? echo TEMPLATE_STYLE;?>">
    </head>
    <body onload="preloadImages();" style="background-color: #8E8B8B;">
    <!-- warnings //-->
    <?php require(DIR_WS_INCLUDES . 'warnings.php'); ?>
    <!-- warning_eof //-->
    
    <!-- header //-->
    <?php require(DIR_WS_TEMPLATES . TEMPLATE_NAME .'/header.php'); ?>
    <!-- header_eof //-->
    <?php
    	// INSERT YOUR WordPress Loop Code HERE:
    	if (have_posts()) :
    	   while (have_posts()) :
    		  the_post();
    		  the_content();
    	   endwhile;
    	endif;
    	// END WordPress Loop Code
    ?>
    <!-- footer //-->
    <?php require(DIR_WS_TEMPLATES . TEMPLATE_NAME .'/footer.php'); ?>
    <!-- footer_eof //-->
    </body>
    </html>
    

    A discussion of The WordPress Loop is beyond the scope of this tutorial; however, here are some excellent resources:

  4. Create the following file: oscommerce_root/includes/languages/your_language/blog.php (Note: This file must be named the same as the file you created in step 1). The contents of this file are as follows:
    <?php
    /*
    Title: Embedding WordPress into OS Commerce
    Author: Michael Wender (www.michaelwender.com)
    Disclaimer: This Software is provided "AS IS" and without warranty of any kind. The user assumes all risks associated with its use and installation.
    
    $Id: blog.php,v 1.2 2004/03/05 00:36:42 ccwjr Exp $
    
    osCommerce, Open Source E-Commerce Solutions
    
    http://www.oscommerce.com
    
    Copyright (c) 2003 osCommerce
    
    Released under the GNU General Public License
    */
    
    define('NAVBAR_TITLE', STORE_NAME. ' Blog');
    define('HEADING_TITLE', 'Blog');
    ?>
    
  5. Okay, your WordPress blog should now be embedded into your OS Commerce install. Keep in mind that you will need to adjust your menus and links to point to this new page you have created. If your OS Commerce install is located in your site’s web root, and you have used the same filenames suggested in this tutorial, then the link to your blog will be: http://your-domain.com/blog.php.

Comments

  1. That was very nice of you to take the time to post your tutorial to help the rest of us out with your expertise. Thanks much!

  2. Thanks for sharing.

  3. Agree! Thanks you very much

  4. Super! I hope it will be simple to setup and change graphic template..

  5. I love your tutorial (and your great design sense!)!

    However, my client’s built-in install of osCommerce does not have a templates sub-directory anywhere, nor does it have different sections in filenames.php… Different versions? Suggestions??

  6. This setup procedure only applies to osCommerce websites which use the Basic Template Structure (BTS), which few osCommerce websites use – for the reason that it makes it very difficult to install additions to osCommerce when BTS is being used. This is why most people who use a template structure with osCommerce choose STS (Simple Template System).

  7. Rhea, thanks for pointing this out. I will have to look into the STS (Simple Template System), and see if it makes my life easier with OSC. Furthermore, I am guessing that your post answers James’ question in his comment prior to yours.

    Thanks!
    Michael

  8. Michael – any update to your tutorial based on the BTS/STS question? Many thanks! B

  9. I got it to work with STS. Think simple…

    Use the STS style filenames instead of BTS i.e. php.html. And, you just have to use the wordpress loop part.

    I will post more when i figure out how to include the sidebar.

  10. i got the to work fine. But i think i used STS Plus instead of just the sts3. Anyone interested in making this a contrib fer OsC?

  11. i got the get_sidebar() to work fine. But i think i used STS Plus instead of just the sts3. Anyone interested in making this a contrib fer OsC?

  12. sorry thats retarded

  13. There is so much you can do with this, I am going to write a part two to this tutorial. Will post it later on my blog. I am still writing a page that uses all the wordpress conditionals.

    i have been developing this OsC site for so long without touching wordpress. a thought…. WordPress Rocks. When will OsC get the same kind of plug-in administration wordpress has. Its just so much easyer to deal with.

  14. Hello,

    Thank a lot for your tuto.

    Most of people doesn’t use an template contribution such as STS or BTS.
    Is there a simple way to adapt your method to intergrate wordpress to an original oscommerce site (MS2.2) ?

    Thanks you for your help.

  15. soundi,

    You make a good point about adapting this tutorial for use with OSC (MS2.2) installs without a template contribution. I will look into this and hopefully publish a part two to this tutorial this next month (October 2006).

  16. if you do so, you’ll be a great man, maybe de man of the year ;-)

  17. Many thanks for this. I had no end of trouble combining OSC with a blog. They had some form of incompatibility that I was only able to solve by putting them both in a spearate subdirectory with a redirect to the blog from the index file. The incompatibility was that OSC would lose its admin panel. I think it was session thing but never got to the bottom of it.

    I’ve yet to work through your solution, but thought I would post this in case anyone else has had the same problem.

  18. There are a lot of people searching for a good wordpress in OSC contribution, myself included. I hope this is it!

  19. Could you tell me what this:

    oscommerce_root/templates/your_template_dir/blog_page.tpl.php

    would be in a standard osc shop?

    Thanks!

  20. Mike,

    As I haven’t had time to examine a standard install of OSC, at this point, I can’t answer your question. However, in the next few weeks, I plan to do a standard OSC install and write part two of this tutorial. When I do that, I should be able to answer your question.

    Thanks,
    Michael

  21. Mike, soundi, and anyone else out there looking for a guide to embedding WordPress into a default install of OSC MS2.2, here is that tutorial I promised you:

    Embedding WordPress into OS Commerce Part II

  22. Thanks for this great intergration.

    I have WordPress with G2 embedded using WPG2. The problem arises with the path to the wp theme stylesheet. What would you suggest when

    @import url( ); prints to:

    @import url( http://www.creativecrib.com/designprices/blog.php/wp-content/themes/connections-reloaded-15/style.css );

    the “blog.php” seems to be the problem.

    Thanks for any help!

    David

  23. Please Michael write again , some informations in this tutorial is missing ( at step 3 and 4 )
    Thank you,

  24. @bogdan – I see where some of the code appears to have gotten knocked out of the post after my recent update of this site. I will try to have the code back in there by sometime on January 2 when I get back in the office.

  25. thank you very much Michael !
    And Best regards from Romania ! I wish you a new great year !

  26. Hi Michael,

    Do you think you might be able to help me figure out why my comments aren’t displaying on my post page? I can see the number of comments on each post on my blog.php page, but when I click into the post the posted comments aren’t visible.

    Would really appreciate anybody’s help on this… thanks!

  27. @gman – The example page that I provide in this tutorial is bare-bones. To add comments to the display, add the following code:

    < ?php comments_template(); ?>

    (Note: At some point, I need to write a Part III to this tutorial as I’ve learned a lot since I first wrote this one and I can probably make this process even easier and more robust.)

  28. Hi Michael,

    Ok I got comments working. I was working with WordPress off a separate database so installing in my existing osc works flawlessly, but now all product pages and cart pages turn up blank. Any ideas? Perhaps you could take a look?

  29. Hi,

    this help me a lot.
    thanks

  30. Thanks!

  31. i just want to thank you, i’ve just started my own website , and that’s what i’ve be looking …. thx alot

  32. Was looking for this thing only :) thanks

  33. sir,
    I am very new to os commerce…
    I found this tutorial very interesting… as i am searching for wp – osc integration.

    but .
    i didnt understand third steps.
    i.e :-Create the following file: oscommerce_root/templates/your_template_dir/blog_page.tpl.php

    In the oscommerce default installation i didnt find any templates folder exist . and also
    where should i define DIR_WS_TEMPLATES, TEMPLATE_NAME?

    I short,
    I am unable to find out
    where should i place blog_page.tpl.php file?

    kindly reply as early as possible.
    thanks in advance.
    Happy New YEar 2010.

  34. Is this technique compatible with the latest version of WordPress? Thanks for the tip btw — Kathleen :)

    • My hunch is that this technique will still work; however, I’m not sure as I haven’t used this technique in a while. Lately, I have been taking advantage of some of the very good e-commerce WordPress plugins that have come out in recent years.

      Feel free to post back with your reports of success or non-success.

  35. Hello,

    I currently using the latest version of OSCommerce and latest version of WordPress but wasn’t successfully embedded the OSCommerce to my wordpress site. There are some sub directories missing already. :(

    • Hi Malditch,

      If you have found out the solution how to integrate WP into OSC please let me know. I am stuck and do not know how to do it?

      Thanks.

  36. cripperfy says:

    Nice article, but if you people need to use an already implemented theme, this is the best one i have used so far: Avada. It has all you want to implement a better than cool website. Check it out

    http://themeforest.net/item/avada-responsive-multipurpose-theme/2833226

    (Note: 02/12/2014 (11:22) – Removed affiliate string from link above. ~MWender)

Trackbacks

  1. [...] OS Commerce is a popular open source ecommerce shopping script that many web developers use to sell goods. Here’s a tutorial on how to embed a WordPress blog into an OS Commerce installation. [...]

  2. [...] ecommerce shopping script that many web developers use to sell goods. Here’s a tutorial on how to embed a WordPress blog into an OS Commerce installation.37. Creating An Automatic SitemapSitemaps help users navigate the site, as well as allow search [...]

  3. [...] OS Commerce 是一个热门的电子商务网站脚本,这个教程教像如何整合wordpress博客到os commerce. how to embed a WordPress blog into an OS Commerce installation. [...]

  4. [...] OS Commerce is a popular open source ecommerce shopping script that many web developers use to sell goods. Here’s a tutorial on how to embed a WordPress blog into an OS Commerce installation. [...]

  5. [...] OS Commerce 是一个热门的电子商务网站脚本,这个教程教像如何整合wordpress博客到os commerce. how to embed a WordPress blog into an OS Commerce installation. [...]

  6. [...] OS Commerce is a popular open source ecommerce shopping script that many web developers use to sell goods. Here’s a tutorial on how to embed a WordPress blog into an OS Commerce installation. [...]

  7. [...] OS Commerce 是一个热门的电子商务网站脚本,这个教程教像如何整合wordpress博客到os commerce. how to embed a WordPress blog into an OS Commerce installation. [...]

  8. [...] can hire them to install and configure osCommerce on your blog. Also you can read and follow this Tutorial where you can learn step by step installation guide for this [...]

  9. [...] 杂项 36. 整合Wordpress 到OS Commerce OS Commerce 是一个热门的电子商务网站脚本,这个教程教像如何整合WordPress博客到os commerce. how to embed a WordPress Blog into an OS Commerce installation. [...]

  10. [...] 257. Embedding WordPress into OS Commerce [...]

  11. [...] 116. Embedding WordPress into OS Commerce [...]

  12. [...] OS Commerce is a popular open source ecommerce shopping script that many web developers use to sell goods. Here’s a tutorial on how to embed a WordPress blog into an OS Commerce installation. [...]

  13. [...] OS Commerce is a popular open source ecommerce shopping script that many web developers use to sell goods. Here’s a tutorial on how to embed a WordPress blog into an OS Commerce installation. [...]

  14. [...] OS Commerce is a popular open source ecommerce shopping script that many web developers use to sell goods. Here’s a tutorial on how to embed a WordPress blog into an OS Commerce installation. [...]

  15. [...] OS Commerce 是一个热门的电子商务网站脚本,这个教程教像如何整合wordpress博客到os commerce. how to embed a WordPress blog into an OS Commerce installation. [...]

  16. [...] OS Commerce is a popular open source ecommerce shopping script that many web developers use to sell goods. Here’s a tutorial on how to embed a WordPress blog into an OS Commerce installation. [...]

  17. [...] OS Commerce is a popular open source ecommerce shopping script that many web developers use to sell goods. Here’s a tutorial on how to embed a WordPress blog into an OS Commerce installation. [...]

  18. [...] OS Commerce is a popular open source ecommerce shopping script that many web developers use to sell goods. Here’s a tutorial on how to embed a WordPress blog into an OS Commerce installation. [...]

  19. [...] OS Commerce is a popular open source ecommerce shopping script that many web developers use to sell goods. Here’s a tutorial on how to embed a WordPress blog into an OS Commerce installation. [...]

  20. [...] Update User Info114. WordPress blog admin settings115. How to Enable HTTPSOther Tutorials116. Embedding WordPress into OS Commerce117. How to Enable HTTPS for WordPress.com Blogs118. Build a Dynamic Design Portfolio119. The [...]

  21. [...] commerce. how to embed a WordPress blog into an OS Commerce installation. 37。创建一个自动的SitemapSitemaps帮助用户对网站进行导航浏览, [...]

  22. [...] 116. Embedding WordPress into OS Commerce [...]

  23. [...] OS Commerce 是一个热门的电子商务网站脚本,这个教程教像如何整合wordpress博客到os commerce. how to embed a WordPress blog into an OS Commerce installation. [...]

  24. [...] OS Commerce 是一个热门的电子商务网站脚本,这个教程教像如何整合wordpress博客到os commerce. how to embed a WordPress blog into an OS Commerce installation. [...]

  25. [...] OS Commerce 是一个热门的电子商务网站脚本,这个教程教像如何整合wordpress博客到os commerce. how to embed a WordPress blog into an OS Commerce installation. [...]

  26. [...] OS Commerce 是一个热门的电子商务网站脚本,这个教程教像如何整合wordpress博客到os commerce. how to embed a WordPress blog into an OS Commerce installation. [...]

  27. [...] recently mentioned that I now prefer to build e-commerce sites using WordPress for the entire setup. In today’s [...]

Leave a Reply