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

If Statement for any page?

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 01-23-2011, 06:08 AM
  promart418's Avatar 
promart418 promart418 is offline
 

Senior Member
  
Join Date: Jan 2009
Location: Leeds, West Yorkshire, England
Posts: 137
 

Default If Statement for any page?

I am using if statements to add category specific code to my site, using:

{if cat eq '1'}
code for category 1 page
{elseif cat eq '2'}
code for category 2 page
etc..

{/if}

I have 2 questions though:

1. How do you do the same for manufacturer, product and static pages?

2. I have roughly 15 categories and 25 manufacturers, so the code would be okay, i.e. not too long. But, my site has ~600 pages, so is there a more concise way of adding custom code to any and every URL?

Thanks,
__________________
x-cart version - 5

Martin Procter

Promart Supplements
Nicola Anne Photography
Reply With Quote
  #2  
Old 01-23-2011, 06:11 AM
  promart418's Avatar 
promart418 promart418 is offline
 

Senior Member
  
Join Date: Jan 2009
Location: Leeds, West Yorkshire, England
Posts: 137
 

Default Re: If Statement for any page?

Further details... the reason I ask is that I was going to add page specific special offers and additional information to my site in the sidebars. This would be an ongoing process, but I don't want to add 600 lines of if/elseif statements to my site.
__________________
x-cart version - 5

Martin Procter

Promart Supplements
Nicola Anne Photography
Reply With Quote
  #3  
Old 01-23-2011, 06:19 AM
  promart418's Avatar 
promart418 promart418 is offline
 

Senior Member
  
Join Date: Jan 2009
Location: Leeds, West Yorkshire, England
Posts: 137
 

Default Re: If Statement for any page?

One more issue, my if statements do not appear to work inside
{php}
code...
{if ...}
code
{elseif ...}
code
{/if}
{/php}

What am I doing wrong? I tried using the literal tags, but to no success.

Thanks again,
__________________
x-cart version - 5

Martin Procter

Promart Supplements
Nicola Anne Photography
Reply With Quote
  #4  
Old 01-23-2011, 07:26 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,191
 

Default Re: If Statement for any page?

If every singl page will have its own different from the others offer you eithr have to do all the if/then lines or you can add extra field and use it for each product page to enter different value

Once you start with {php} in a template you have to use php syntax

{php}
code...
if (whatever) {
code
} elseif (whatever) {
code
} else {
code
}
{/php}
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #5  
Old 01-23-2011, 07:57 AM
  promart418's Avatar 
promart418 promart418 is offline
 

Senior Member
  
Join Date: Jan 2009
Location: Leeds, West Yorkshire, England
Posts: 137
 

Default Re: If Statement for any page?

Thanks, but I am still having problems with understanding the code. I have:

Code:
{php} require_once('simplepie.inc'); $feed = new SimplePie(); if($cat eq "252"){$feed->set_feed_url('http://www.promartsupplements.co.uk/blog/category/all-in-ones/?feed=rss2');} else {$feed->set_feed_url('http://www.promartsupplements.co.uk/blog/?feed=rss2');} $feed->init(); // Limit the items to be shown $i = 0; foreach($feed->get_items() as $item){ if($i <= 2){ echo '<h3 style="font-size:14px;"><a style="color:#000; text-decoration:none; font-size:13px; font-family:Verdana,Arial,Helvetica,Sans-serif;" href="'.$item->get_permalink().'">'.$item->get_title().'</a> </h3>'; echo '<p style="font-family:Verdana,Arial,Helvetica,Sans-serif; font-size:11px;">'.substr($item->get_description(),0,180).'...<a style="text-decoration:none; font-size:11px; font-family:Verdana,Arial,Helvetica,Sans-serif;" href="'.$item->get_permalink().'">[Read Article]</a></p>'; $i++; } } {/php}

I'm sure whatever I have done wrong is minor, but I can't fathom it.
__________________
x-cart version - 5

Martin Procter

Promart Supplements
Nicola Anne Photography
Reply With Quote
  #6  
Old 01-23-2011, 07:59 AM
  promart418's Avatar 
promart418 promart418 is offline
 

Senior Member
  
Join Date: Jan 2009
Location: Leeds, West Yorkshire, England
Posts: 137
 

Default Re: If Statement for any page?

All of the code worked fine until I added the if/else part. Originally, the blog feed integration was the same on every page and that is what I am trying to change.

Thanks,
__________________
x-cart version - 5

Martin Procter

Promart Supplements
Nicola Anne Photography
Reply With Quote
  #7  
Old 01-23-2011, 08:26 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,191
 

Default Re: If Statement for any page?

Like I said - you can't use smarty syntax within php code and yet you are doing it (there is no "eq" in php)

Code:
{php} require_once("simplepie.inc"); $feed = new SimplePie(); if($cat == "252") $feed->set_feed_url("http://www.promartsupplements.co.uk/blog/category/all-in-ones/?feed=rss2"); else $feed->set_feed_url("http://www.promartsupplements.co.uk/blog/?feed=rss2"); $feed->init(); // Limit the items to be shown $i = 0; foreach($feed->get_items() as $item) { if($i <= 2) { echo "<h3 style='font-size:14px;'><a style='color:#000; text-decoration:none; font-size:13px; font-family:Verdana,Arial,Helvetica,Sans-serif;' href='" . $item->get_permalink() . "'>" . $item->get_title() . "</a> </h3>"; echo "<p style='font-family:Verdana,Arial,Helvetica,Sans-serif; font-size:11px;'>" . substr($item->get_description(),0,180) . "...<a style='text-decoration:none; font-size:11px; font-family:Verdana,Arial,Helvetica,Sans-serif;' href='" . $item->get_permalink(). "'>[Read Article]</a></p>"; $i++; } } {/php}
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #8  
Old 01-23-2011, 09:01 AM
  ADDISON's Avatar 
ADDISON ADDISON is offline
 

X-Man
  
Join Date: Jan 2008
Posts: 2,613
 

Default Re: If Statement for any page?

it is not recommended to use {php}{/php} in smarty template files. if is used, do not abuse of it.
__________________
X-Cart Next: Business 5.2 (learning and testing)
X-Cart Classic: Gold and Gold Plus 4.7
Lots of Modules and Customizations
OS in use: Red Hat Enterprise, Fedora, CentOS, Debian, Ubuntu, Linux Mint, Kali Linux
Ideas for Server configuration (basicaly): Nginx/Pound (reverse proxy), Apache/Nginx (webserver), Squid/Varnish (cache server), HHVM or (PHP-FPM + PHP 5.6 + opcache), MariaDB/Percona MySQL Server, Redis (storing sessions)

You can catch my ideas here: http://ideas.x-cart.com
Reply With Quote
  #9  
Old 01-23-2011, 09:57 AM
  promart418's Avatar 
promart418 promart418 is offline
 

Senior Member
  
Join Date: Jan 2009
Location: Leeds, West Yorkshire, England
Posts: 137
 

Default Re: If Statement for any page?

Thanks for your help. I am a novice with php and mysql, so most of it looks foreign to me at the moment. The code was written by a third party and I just wanted to tweak it.

I tried the above, which doesn't crash the site like when I did it myself, but the feed is the same on both pages. I'm wondering if I need to declare the $cat variable before calling it (please excuse my terminology).

p.s. categoryid no. 252 in my MySQL table is the all-in-one category, so I was hoping that page would show a different feed integration category.

Thanks,
__________________
x-cart version - 5

Martin Procter

Promart Supplements
Nicola Anne Photography
Reply With Quote
  #10  
Old 01-23-2011, 09:58 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,191
 

Default Re: If Statement for any page?

Depends on the page you are calling this form $cat may not be defined at all
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



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 01:38 AM.

   

 
X-Cart forums © 2001-2020