X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   If Statement for any page? (https://forum.x-cart.com/showthread.php?t=57688)

promart418 01-23-2011 06:08 AM

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,

promart418 01-23-2011 06:11 AM

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.

promart418 01-23-2011 06:19 AM

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,

cflsystems 01-23-2011 07:26 AM

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}

promart418 01-23-2011 07:57 AM

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.

promart418 01-23-2011 07:59 AM

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,

cflsystems 01-23-2011 08:26 AM

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}


ADDISON 01-23-2011 09:01 AM

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.

promart418 01-23-2011 09:57 AM

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,

cflsystems 01-23-2011 09:58 AM

Re: If Statement for any page?
 
Depends on the page you are calling this form $cat may not be defined at all

promart418 01-23-2011 10:01 AM

Re: If Statement for any page?
 
I think what I am trying to ask is how do you call a specific categoryid from the MySQL database in the simplest way in x-cart?

EDIT... I was replying to my own post, but you responded before I submitted and my response looks a bit rude, sorry about that, not intended.

ARW VISIONS 01-23-2011 10:12 AM

Re: If Statement for any page?
 
maybe this?

Code:

{if $cat eq "252"}

{php}
require_once("simplepie.inc");
$feed = new SimplePie();
 $feed->set_feed_url("http://www.promartsupplements.co.uk/...nes/?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}

{else}

{php}
require_once("simplepie.inc");
$feed = new SimplePie();
 $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}

{/if}


promart418 01-23-2011 12:03 PM

Re: If Statement for any page?
 
Thanks Ashley. I will implement that.

My aim is to increase unique and relevant content on my x-cart category pages, by pulling in the most recent 3 blog articles from my wordpress blog feed for the same category, i.e.

The most recent 3 article snippets from ".co.uk/blog/category/cat1/feed/" showing on ".co.uk/cat1"

I want to do this on 20ish category pages and 30ish manufacturer pages, without adding loads of additional code.

My last SEO company could not achieve this, so I am trying to do it myself. Do you think the method you suggested would be okay when applied to about 50 pages?

I use GZIP, so I suppose it shouldn't increase page load times much at all, even if it does add lots of code.

If you know a better method though, please let me know,

Thanks,

ARW VISIONS 01-23-2011 03:01 PM

Re: If Statement for any page?
 
I would do it like this.

make a .tpl for each cat wit the cat id in the name

so

252_feed.tpl

the do it like this.

{include file="customer/feeds/`$cat`_feed.tpl"}

of course you need to make the customer/feed folder.

then in your 252_feed.tpl file put your php code

{php}
require_once("simplepie.inc");
$feed = new SimplePie();
$feed->set_feed_url("http://www.promartsupplements.co.uk/...nes/?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}

cflsystems 01-23-2011 04:58 PM

Re: If Statement for any page?
 
If this is for category pages then $cat will work - $cat holds the current category id. But you should put your code in include/categories.php and assign the result to smarty. Then you can use that smarty variable in a template to show the links

sinobest 01-23-2011 05:02 PM

Re: If Statement for any page?
 
would you please tell up the details on how to add the code? Where should we put simplepie.inc? many thanks.

cflsystems 01-23-2011 05:29 PM

Re: If Statement for any page?
 
You can copy the inc file in include directory. In include/categories.php just before "?>" put

Code:

require_once $xcart_dir."/include/simplepie.inc";
$feed = new SimplePie();
if($cat == 252)
 $feed->set_feed_url("http://www.promartsupplements.co.uk/...nes/?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;
$new_feed = array();
foreach($feed->get_items() as $item) {
 if($i <= 2) {
$new_feed[$i]["link"] = $item->get_permalink();
$new_feed[$i]["title"] = $item->get_title();
$new_feed[$i]["descr"] = substr($item->get_description(),0,180);
 
$i++;
 }
}
$smarty->assign("new_feed", $new_feed);


Then use $new_feed in the template you want it to show

Code:


{foreach from=$new_feed item=nf}
<a href="{$nf.link}">{$nf.title}</a>
<br />
{$nf.descr}
 
<p> ----------------------------------</p>
{/foreach}


sinobest 01-23-2011 08:05 PM

Re: If Statement for any page?
 
i can not find categories.php under include category, i only find one under admin category. i am using x-cart 4.4.2 gold

cflsystems 01-24-2011 05:03 AM

Re: If Statement for any page?
 
There is no categories.php for 4.4.x, the replacement is common.php

promart418 01-30-2011 04:38 AM

Re: If Statement for any page?
 
Hi all,

I just wanted to say thanks for all the great information. It is slightly beyond my abilities at the moment, but I will come back to it as I learn, thanks again.


All times are GMT -8. The time now is 01:30 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.