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
  #11  
Old 01-23-2011, 10:01 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?

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.
__________________
x-cart version - 5

Martin Procter

Promart Supplements
Nicola Anne Photography
Reply With Quote
  #12  
Old 01-23-2011, 10:12 AM
  ARW VISIONS's Avatar 
ARW VISIONS ARW VISIONS is offline
 

X-Man
  
Join Date: Jan 2007
Location: Pensacola, FL
Posts: 2,536
 

Default 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}
__________________
xcart 5.1.2
Reply With Quote

The following user thanks ARW VISIONS for this useful post:
promart418 (01-23-2011)
  #13  
Old 01-23-2011, 12:03 PM
  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 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,
__________________
x-cart version - 5

Martin Procter

Promart Supplements
Nicola Anne Photography
Reply With Quote
  #14  
Old 01-23-2011, 03:01 PM
  ARW VISIONS's Avatar 
ARW VISIONS ARW VISIONS is offline
 

X-Man
  
Join Date: Jan 2007
Location: Pensacola, FL
Posts: 2,536
 

Default 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}
__________________
xcart 5.1.2
Reply With Quote
  #15  
Old 01-23-2011, 04:58 PM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default 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
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #16  
Old 01-23-2011, 05:02 PM
 
sinobest sinobest is offline
 

X-Adept
  
Join Date: Nov 2009
Posts: 461
 

Default 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.
__________________
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
  #17  
Old 01-23-2011, 05:29 PM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default 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}
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #18  
Old 01-23-2011, 08:05 PM
 
sinobest sinobest is offline
 

X-Adept
  
Join Date: Nov 2009
Posts: 461
 

Default 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
__________________
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
  #19  
Old 01-24-2011, 05:03 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,190
 

Default Re: If Statement for any page?

There is no categories.php for 4.4.x, the replacement is common.php
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote

The following user thanks cflsystems for this useful post:
sinobest (01-24-2011)
  #20  
Old 01-30-2011, 04:38 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?

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.
__________________
x-cart version - 5

Martin Procter

Promart Supplements
Nicola Anne Photography
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 05:19 PM.

   

 
X-Cart forums © 2001-2020