Home

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.

30 Comments

  1. Leo FishReply to this comment
    Dec. 8, 2005, 11:18 pm
    Permalink

    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. Dec. 13, 2005, 10:45 am
    Permalink

    Thanks for sharing.


  3. Dec. 14, 2005, 5:50 pm
    Permalink

    Agree! Thanks you very much


  4. Dec. 19, 2005, 4:30 am
    Permalink

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


  5. Jan. 15, 2006, 2:31 pm
    Permalink

    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. Mar. 19, 2006, 8:23 am
    Permalink

    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. Mar. 19, 2006, 3:41 pm
    Permalink

    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. Apr. 24, 2006, 3:22 am
    Permalink

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


  9. AdamReply to this comment
    Apr. 25, 2006, 2:12 pm
    Permalink

    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. Apr. 25, 2006, 4:19 pm
    Permalink

    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. Apr. 25, 2006, 4:20 pm
    Permalink

    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. Apr. 25, 2006, 5:49 pm
    Permalink

    sorry thats retarded


  13. Apr. 28, 2006, 11:38 am
    Permalink

    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. soundiReply to this comment
    Sep. 24, 2006, 3:43 am
    Permalink

    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. Sep. 25, 2006, 9:34 am
    Permalink

    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. soundiReply to this comment
    Sep. 25, 2006, 5:44 pm
    Permalink

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


  17. Sep. 26, 2006, 2:38 am
    Permalink

    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. Sep. 26, 2006, 6:24 am
    Permalink

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


  19. Sep. 27, 2006, 4:26 am
    Permalink

    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. Sep. 27, 2006, 1:32 pm
    Permalink

    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. Oct. 6, 2006, 3:15 pm
    Permalink

    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. Dec. 20, 2006, 8:03 am
    Permalink

    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. Dec. 29, 2007, 8:22 am
    Permalink

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


  24. Dec. 29, 2007, 11:22 am
    Permalink

    @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. Jan. 3, 2008, 4:05 pm
    Permalink

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


  26. gmanReply to this comment
    Jan. 27, 2008, 2:38 am
    Permalink

    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. Jan. 27, 2008, 8:44 am
    Permalink

    @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. gmanReply to this comment
    Jan. 27, 2008, 11:56 am
    Permalink

    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. MaheshReply to this comment
    Apr. 29, 2008, 12:59 am
    Permalink

    Hi,

    this help me a lot.
    thanks


  30. May. 16, 2008, 3:15 pm
    Permalink

    Thanks!


Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*