Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

How to add php code?

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 05-07-2010, 05:06 AM
 
sinobest sinobest is offline
 

X-Adept
  
Join Date: Nov 2009
Posts: 462
 

Default How to add php code?

i want to add som php code to home_main.tpl, how to do?
__________________
X-Cart Version: 4.7.12 GOLD
www.cheapglasses123.com prescription glasses online at discounted prices.
prescriptionglassesusa.com
www.loupesusa.com X-Cart Version: 4.7.11 GOLD PLUS
Reply With Quote
  #2  
Old 05-07-2010, 05:32 AM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default Re: How to add php code?

You can't add php code to templates, you need to add it to the php files - what exactly are you trying to do?
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #3  
Old 05-07-2010, 10:20 AM
 
Shamun Shamun is offline
 

X-Adept
  
Join Date: Jun 2009
Location: North Carolina
Posts: 841
 

Default Re: How to add php code?

You can add php code to the .tpl files using {php}{/php} but for simplicity you should be adding it to a .php file outside of the /skin1/ directory tree.
__________________
- Shane Munroe
Reply With Quote
  #4  
Old 05-07-2010, 12:33 PM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default Re: How to add php code?

Sorry, I should have said 'It is not good practice to add php to the templates'
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #5  
Old 05-09-2010, 07:57 AM
 
sinobest sinobest is offline
 

X-Adept
  
Join Date: Nov 2009
Posts: 462
 

Default Re: How to add php code?

for example, i want to add the following php code to x-cart:
Code:
<?php // Include Wordpress define('WP_USE_THEMES', false); require('../../wp/en/glasses/wp-load.php'); query_posts('showposts=5'); ?> <?php while (have_posts()): the_post(); ?> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <?php the_excerpt(); ?> <p><a href="<?php the_permalink(); ?>">Read more...</a></p> <?php endwhile; ?>

how to do?

tks.
__________________
X-Cart Version: 4.7.12 GOLD
www.cheapglasses123.com prescription glasses online at discounted prices.
prescriptionglassesusa.com
www.loupesusa.com X-Cart Version: 4.7.11 GOLD PLUS
Reply With Quote
  #6  
Old 05-09-2010, 01:19 PM
 
Shamun Shamun is offline
 

X-Adept
  
Join Date: Jun 2009
Location: North Carolina
Posts: 841
 

Default Re: How to add php code?

Just so you know, it probably won't work.
If Wordpress has any php functions with the same names as in X-cart (which is likely) then you'll have errors. You will probably have session problems as well.

As for how, I believe you'll need to put that into init.php
You will also need to assign the php variables as smarty variables to call via {$variable} in your template.
__________________
- Shane Munroe
Reply With Quote
  #7  
Old 05-10-2010, 06:08 PM
 
sinobest sinobest is offline
 

X-Adept
  
Join Date: Nov 2009
Posts: 462
 

Default Re: How to add php code?

how to do, pls?
__________________
X-Cart Version: 4.7.12 GOLD
www.cheapglasses123.com prescription glasses online at discounted prices.
prescriptionglassesusa.com
www.loupesusa.com X-Cart Version: 4.7.11 GOLD PLUS
Reply With Quote
  #8  
Old 06-24-2010, 04:39 AM
 
sinobest sinobest is offline
 

X-Adept
  
Join Date: Nov 2009
Posts: 462
 

Default Re: How to add php code?

anybody can share his skills?
tks.
__________________
X-Cart Version: 4.7.12 GOLD
www.cheapglasses123.com prescription glasses online at discounted prices.
prescriptionglassesusa.com
www.loupesusa.com X-Cart Version: 4.7.11 GOLD PLUS
Reply With Quote
  #9  
Old 06-24-2010, 05:44 AM
 
Shamun Shamun is offline
 

X-Adept
  
Join Date: Jun 2009
Location: North Carolina
Posts: 841
 

Default Re: How to add php code?

Your wanting to use non-xcart and non-smarty code in an xcart and smarty environment. Not to mention wordpress is huge...

You should talk to qualiteam, bcse etc. if you really want it done.
__________________
- Shane Munroe
Reply With Quote
  #10  
Old 06-24-2010, 05:50 AM
 
geckoday geckoday is offline
 

X-Wizard
  
Join Date: Aug 2005
Posts: 1,073
 

Default Re: How to add php code?

To avoid conflicts with X-Cart you should pull the Wordpress posts using an RSS feed. I created a Smarty plugin to do this. Create a file include/templater/plugins/function.sr_wpfeed.php with this code:

PHP Code:
<?php
if ( !defined('XCART_START') ) { header("Location: home.php"); die("Access denied"); }
## -----------------------------------------------------------------------------
## Smarty plugin "sr_wpfeed"
## Purpose: Return wordpress RSS feed
##          Snow River X-Cart web store
##
## Author: Ralph Day, Snow River
##
##
## -----------------------------------------------------------------------------
##
## Changelog:
##
## 2009-10-26 Created (RD)
##
##
## -----------------------------------------------------------------------------
##
##
## Sample usage
## ------------
## {sr_wpfeed var="someposts" wpsite="http://www.snowriver.com/uggs-and-more" num=2}
## <foreach from=$someposts item=somepost>
##   {$somepost.link}
##   {$somepost.title}
##   {$somepost.description}
## </foreach>
## 
##
## Parameters
## ----------
## var [string] (required)
##      Name for Smarty variable to return feed array in
## 
## wpsite [string] (required)
##      URL of Wordpress site
## 
## num [integer] (required)
##      number of posts to return
## 
## 
## -----------------------------------------------------------------------------

function smarty_function_sr_wpfeed($params, &$smarty) {

  global 
$sql_tbl;
  global 
$store_language;

  
$required_params = array('var','wpsite''num');

  foreach(
$required_params as $_key => $reqd_param) {
    if (!isset(
$params[$reqd_param]))
      
$smarty->trigger_error("sr_wpfeed: required attribute '$reqd_param' not passed"E_USER_ERROR);
  }

  
$var      '';
  
$wpsite '';
  
$num 0;
  foreach(
$params as $_key => $_val) {
    switch(
$_key) {
      case 
'wpsite':
      case 
'var':
          if (!
is_array($_val)) {
              if (
$_val <> '')
                $
$_key $_val;
              else
                
$smarty->trigger_error("sr_wpfeed: '$_key' cannot be an empty string"E_USER_ERROR);
          } else
              
$smarty->trigger_error("sr_wpfeed: '$_key' cannot be an array"E_USER_ERROR);
          break;
          
      case 
'num':
          if (!
is_array($_val)) {
            $
$_key = (int)$_val;
            if ($
$_key || $$_key >25)
                
$smarty->trigger_error("sr_wpfeed: '$_key' not between 1 and 25"E_USER_ERROR);
          } else
              
$smarty->trigger_error("sr_wpfeed: '$_key' cannot be an array"E_USER_ERROR);
          break;

      default:
          
$smarty->trigger_error("sr_wpfeed: attribute '$_key' not recognized"E_USER_NOTICE);
          break;
    }
  }
    if(!
$xml=simplexml_load_file($wpsite.'/feed')){
        
trigger_error('Error reading XML file',E_USER_ERROR);
    }
  
$posts = array();
    foreach(
$xml as $item){
        for(
$i=0$i<count($item->item); $i++){
            if(
$i<$num){
        
$posts[] = array('link'         =>  (string)$item->item[$i]->link
                       
'title'        =>  htmlentities($item->item[$i]->title,ENT_COMPAT'UTF-8')
                       , 
'description'  =>  $item->item[$i]->description
                       
);
      }
        }
    }

  
$smarty->assign($var$posts);
}
?>

The sample usage comments in the code shows what you can drop into your desired .tpl file to display the posts.
__________________
Manuka Bay Company
X-Cart Version 4.0.19 [Linux]

UGG Boots and other fine sheepskin products
http://www.snowriver.com
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 08:29 AM.

   

 
X-Cart forums © 2001-2020