Marshall
Ecommerce Template Guru
USA
1916 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
42874 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 SoftwareClick Here to sign up for our newsletterClick Here for the latest updater
|
Marshall
Ecommerce Template Guru
USA
1916 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. MarshallCENLYT 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
1916 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. MarshallCENLYT Productions - ms designs Affordable Web Design Custom Ecommerce Designs Responsive Websites Cenlyt.com
|
Vince
Administrator
42874 Posts |
Posted - 07/20/2022 : 00:09:20
|
Marshall
Ecommerce Template Guru
USA
1916 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
42874 Posts |
Posted - 07/21/2022 : 01:35:00
|
Marshall
Ecommerce Template Guru
USA
1916 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
1916 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
42874 Posts |
Posted - 07/22/2022 : 06:32:52
|
Marshall
Ecommerce Template Guru
USA
1916 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
42874 Posts |
Posted - 07/22/2022 : 13:00:18
|
Marshall
Ecommerce Template Guru
USA
1916 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'] . '">'; } } ?>
MarshallCENLYT Productions - ms designs Affordable Web Design Custom Ecommerce Designs Responsive Websites Cenlyt.com
|
|
|