Ecommerce software home
Shopping Cart Software Forum for Ecommerce Templates
 
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

Find us on Facebook Follow us on Twitter View our YouTube channel
Search our site
 All Forums
 Technical
 PHP (Unix / Linux / Apache) versions
 Canonical Links for ALT ID/Product Variants SOLVED
Author « Topic »  

Marshall
Ecommerce Template Guru

USA
1875 Posts

Posted - 07/18/2022 :  04:24:37  
According to a recent Google SEO tips video, product variation (I use ALT IDs) should have their own landing page URL. However, the page should have a canonical link to the parent so Google can understand the relationship and prioritize indexing. To this end, I created a pCustom4 column in the products table and placed the parent URLs there, but I cannot get it to write them to the page.

Basically I am looking to get
if(!empty($pCustom4)) {print '<link rel="canonical" href="$pCustom4">'};
This would be placed below the page meta description.

The site is on PHP v7.4.8 and has over 3,000 ALT ID products, so doing this dynamically would be the ideal solution.

Any assistance will be appreciated. And if you are interested in the video, it is here https://www.youtube.com/watch?v=sGyZqUs9XqA

Marshall

Marshall
CENLYT Productions - ms designs
Affordable Web Design
Custom Ecommerce Designs
Responsive Websites
Cenlyt.com

Edited by - Marshall on 08/06/2022 22:26:15

Vince
Administrator

42488 Posts

Posted - 07/18/2022 :  04:48:39  
Hi Marshall
Can you try this bit of code which has to come after the metainfo.php include...

<?php
if($prodid!=''){
$sSQL="SELECT pID,pCustom4 FROM products WHERE pID='" . escape_string($prodid) . "' OR pName='" . escape_string($prodid) . "'";
$result=ect_query($sSQL) or ect_error();
if($rs=ect_fetch_assoc($result)){
print '<link rel="canonical" href="' . $rs['pCustom4'] . '">';
}
}
?>

You'll see there that I'm searching for the product id OR the product name. Actually you only need one or the other of those depending if you are using the product ID or name as the index.

Vince

Click Here for Shopping Cart Software
Click Here to sign up for our newsletter
Click Here for the latest updater

Marshall
Ecommerce Template Guru

USA
1875 Posts

Posted - 07/18/2022 :  05:40:47  
First, the test needs to be if pCustom4 is not empty as the canonical links only apply to the ALT ID products.

Second, I am seeing this at the top of the page
SELECT pID,pCustom4 FROM products WHERE pID='TEST-PRODUCT' OR pName='TEST-PRODUCT'
and no canonical link is being generated.

I guess I should note I am using this on a static detail page for testing with the below in the <head>
<?php
$explicitid="TEST-PRODUCT";
$prodid="TEST-PRODUCT";
?>
and this in the body
<?php include "vsadmin/inc/incproddetail.php" ?>
And yes, the
<?php include "vsadmin/inc/metainfo.php" ?>
is above the script you just provided.

If I need to try this on a live regular proddetail.php page, I will do that later. Rather not try that during "business hours" in case something goes wrong

UPDATE
I fixed it from printing this
SELECT pID,pCustom4 FROM products WHERE pID='TEST-PRODUCT' OR pName='TEST-PRODUCT'

by commenting out this //print $sSQL."\n";
Still, need it to only do the canonical link when pCustom4 is not empty, otherwise I will have to put canonical links in every product, even those that do not need them.

Marshall
CENLYT Productions - ms designs
Affordable Web Design
Custom Ecommerce Designs
Responsive Websites
Cenlyt.com

Edited by - Marshall on 07/18/2022 08:06:04

Marshall
Ecommerce Template Guru

USA
1875 Posts

Posted - 07/18/2022 :  20:34:55  
TEST FAILED. Tried this on the live proddetail.php with no success.
<?php
if($prodid!=''){
$sSQL="SELECT pID,pCustom4 FROM products WHERE pID='" . escape_string($prodid) . "' OR pName='" . escape_string($prodid) . "'";
//print $sSQL."\n";
$result=ect_query($sSQL) or ect_error();
if($rs=ect_fetch_assoc($result)) {
print '<link rel="canonical" href="' . $rs['pCustom4'] . '">';
}
}
?>
Even tried removing this
OR pName='" . escape_string($prodid) . "'
but made no difference.

Marshall
CENLYT Productions - ms designs
Affordable Web Design
Custom Ecommerce Designs
Responsive Websites
Cenlyt.com

Vince
Administrator

42488 Posts

Posted - 07/20/2022 :  00:09:20  
Hi Marshall
Ooops, that print $sSQL."\n"; was a bit of debug that shouldn't have been there. But could you uncomment it again and then refresh the page and view the page source and let me know what the SQL statement is?
I presume TEST FAILED means you didn't get a canonical link rather than any kind of error, no?

Vince

Click Here for Shopping Cart Software
Click Here to sign up for our newsletter
Click Here for the latest updater

Marshall
Ecommerce Template Guru

USA
1875 Posts

Posted - 07/20/2022 :  03:56:56  
It did not print the canonical link. It is important though that it be based not on if pID!="" for printing it, but on if pCustom4 !="" Make sense? And it did not throw any error, just did not print the canonical link.

Marshall
CENLYT Productions - ms designs
Affordable Web Design
Custom Ecommerce Designs
Responsive Websites
Cenlyt.com

Vince
Administrator

42488 Posts

Posted - 07/21/2022 :  01:35:00  
Hi Marshall

You haven't sent me the SQL I requested.

This will check if the pCustom4 is blank...

<?php
if($prodid!=''){
$sSQL="SELECT pID,pCustom4 FROM products WHERE pID='" . escape_string($prodid) . "' OR pName='" . escape_string($prodid) . "'";
//print $sSQL."\n";
$result=ect_query($sSQL) or ect_error();
if($rs=ect_fetch_assoc($result)) {
if(trim($rs['pCustom4'])!='')
print '<link rel="canonical" href="' . $rs['pCustom4'] . '">';
}
}
?>

Vince

Click Here for Shopping Cart Software
Click Here to sign up for our newsletter
Click Here for the latest updater

Marshall
Ecommerce Template Guru

USA
1875 Posts

Posted - 07/21/2022 :  06:24:05  
"You haven't sent me the SQL I requested."

There was no statement, just nothing. I will try the new code later and keep you posted.

Marshall
CENLYT Productions - ms designs
Affordable Web Design
Custom Ecommerce Designs
Responsive Websites
Cenlyt.com

Marshall
Ecommerce Template Guru

USA
1875 Posts

Posted - 07/21/2022 :  21:02:16  
Vince, the script did not work nor was there any error message.

Marshall
CENLYT Productions - ms designs
Affordable Web Design
Custom Ecommerce Designs
Responsive Websites
Cenlyt.com

Vince
Administrator

42488 Posts

Posted - 07/22/2022 :  06:32:52  
Hi Marshall
quote:
Can you try this bit of code which has to come after the metainfo.php include...
Did you put this after the metainfo.php include? It's this include file which will set the $prodid value. You could try displaying that value with say...
print '$prodid is: ' . $prodid . "<br>";

Vince

Click Here for Shopping Cart Software
Click Here to sign up for our newsletter
Click Here for the latest updater

Marshall
Ecommerce Template Guru

USA
1875 Posts

Posted - 07/22/2022 :  10:34:43  
THis print '$prodid is: ' . $prodid . "<br>"; printed the product name. Instead of prodid, should it maybe be productid? I noticed that in the inc/metainfo.php script around line
98 $productid=str_replace('"','"',strip_tags($rs['pID']));

Marshall
CENLYT Productions - ms designs
Affordable Web Design
Custom Ecommerce Designs
Responsive Websites
Cenlyt.com

Vince
Administrator

42488 Posts

Posted - 07/22/2022 :  13:00:18  
Hi Marshall
Sure thing and that sounds like a plan. Try it and see how it goes.

Vince

Click Here for Shopping Cart Software
Click Here to sign up for our newsletter
Click Here for the latest updater

Marshall
Ecommerce Template Guru

USA
1875 Posts

Posted - 08/06/2022 :  22:25:41  
Sorry about the delay in the followup, but this worked. Changing prodid to productid solved the problem.
<?php
if($productid!=''){
$sSQL="SELECT pID,pCustom4 FROM products WHERE pID='" . escape_string($productid) . "'";
//print $sSQL."\n";
$result=ect_query($sSQL) or ect_error();
if($rs=ect_fetch_assoc($result)) {
if(trim($rs['pCustom4'])!='')
print '<link rel="canonical" href="' . $rs['pCustom4'] . '">';
}
}
?>


Marshall
CENLYT Productions - ms designs
Affordable Web Design
Custom Ecommerce Designs
Responsive Websites
Cenlyt.com
  « Topic »  
Jump To:
Shopping Cart Software Forum for Ecommerce Templates © 2002-2022 ecommercetemplates.com
This page was generated in 0.03 seconds. Snitz Forums 2000