Forums / Templates, Stylesheets, Page Layout / Do stuff on product id

Do stuff on product id

Views: 7,194

Results 1 to 15 of 15
28 Aug 2019, 4:01 PM
#1
nick1973 avatar

nick1973

Totally Zenned

Join Date:
Sep 2008
Location:
Cleethorpes
Posts:
1,230
Plugin Contributions:
3

Do stuff on product id

I am trying to generate HTML for something in the head section on product information pages only.

So what would be the correct way to write something like this?

if ($current_page_base == 'index' and $cPath == '1' and $products_id == '123') {
  echo 'DO STUFF';
}

Nick Smith - Venture Design and Print
https://venturedesignandprint.co.uk

28 Aug 2019, 5:24 PM
#2
nick1973 avatar

nick1973

Totally Zenned

Join Date:
Sep 2008
Location:
Cleethorpes
Posts:
1,230
Plugin Contributions:
3

Re: Do stuff on product id

I've tried a few different variations, no success though. Thought something like this might work.

if ($current_page_base == 'product_info' and $products_id == '123') {  echo 'DO STUFF';} 

what I am trying to is output an AMP Page URL for product information pages. I can do this on categories by doing this.

if ($current_page_base == 'index' and $cPath == 'YOUR_CATEGORY_ID') {  echo '<link rel="amphtml" type="text/css" href="https://yoururl.com/your-category-name-or-url">';}

But can't see how I would do similar for a product information page. I need to be able to specify the exact product information page id in a similar way to $cPath == 'YOUR_CATEGORY_ID'

Nick Smith - Venture Design and Print
https://venturedesignandprint.co.uk

28 Aug 2019, 7:51 PM
#3
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,720
Plugin Contributions:
56

Re: Do stuff on product id

I suspect $products_id is not set at the point you are injecting your code. Try using $_GET['products_id'].

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

28 Aug 2019, 10:26 PM
#4
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Do stuff on product id

And if your product has attributes, would recommend casting the $_GET['products_id'] to an integer otherwise when clicking on a product link in the shopping cart the "message" will not be displayed.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

28 Aug 2019, 11:10 PM
#5
nick1973 avatar

nick1973

Totally Zenned

Join Date:
Sep 2008
Location:
Cleethorpes
Posts:
1,230
Plugin Contributions:
3

Re: Do stuff on product id

ok this worked

if ($current_page_base == 'product_info' and $_GET['products_id'] == '123') {  echo '<link rel="amphtml" type="text/css" href="https://MYDOMAINNAME.com/my-url-1.html">';} 
if ($current_page_base == 'product_info' and $_GET['products_id'] == '234') {  echo '<link rel="amphtml" type="text/css" href="https://MYDOMAINNAME.com/my-url-2.html">';}

You would keep repeating the entries in tpl_main_page.php and where it reads $_GET['products_id'] == '234') - enter your product id.

<link rel="amphtml" type="text/css" href="https://MYDOMAINNAME.com/my-url-2.html">
``` - would be the link to your AMP page


Thanks for the help guys, if you have anything else to add to this please let me know

Nick Smith - Venture Design and Print
https://venturedesignandprint.co.uk

29 Aug 2019, 5:46 AM
#6
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Do stuff on product id

To make your page(s) more flexible for relocation, would suggest that the destination links be made more generic so that one doesn't have to update the domain name or the connection method. If the page is located in the root of the catalog then need only to have the href="my-url-2.html" as an example.
If it is at the root of the domain (where the catalog is found in a sub-folder), then thought should be able to use href="/my-url-2.html".

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

29 Aug 2019, 7:20 AM
#7
nick1973 avatar

nick1973

Totally Zenned

Join Date:
Sep 2008
Location:
Cleethorpes
Posts:
1,230
Plugin Contributions:
3

Re: Do stuff on product id

mc12345678:

To make your page(s) more flexible for relocation, would suggest that the destination links be made more generic so that one doesn't have to update the domain name or the connection method. If the page is located in the root of the catalog then need only to have the href="my-url-2.html" as an example.
If it is at the root of the domain (where the catalog is found in a sub-folder), then thought should be able to use href="/my-url-2.html".

OK yes I get your point and thanks for that. I will look into it. There are some pages that can't go in the root as there are already lightweight HTML landing pages with similar names. But I think the product pages could go there.

Nick Smith - Venture Design and Print
https://venturedesignandprint.co.uk

29 Aug 2019, 11:21 PM
#9
nick1973 avatar

nick1973

Totally Zenned

Join Date:
Sep 2008
Location:
Cleethorpes
Posts:
1,230
Plugin Contributions:
3

Re: Do stuff on product id

dbltoe:

Excellent info on relative links at https://www.w3schools.com/html/html_filepaths.asp

Yeah I know all that but I am just not sure if it works the same for AMP pages as they appear to recommend the full URL including the domain name. I suppose the only way to find out though is try it.

Nick Smith - Venture Design and Print
https://venturedesignandprint.co.uk

29 Aug 2019, 11:36 PM
#10
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,845
Plugin Contributions:
17

Re: Do stuff on product id

Starting in 2016 and continuing through 2018, they say use https://... At least that won't cause the mixed content warning on a site.

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com

29 Aug 2019, 11:40 PM
#11
nick1973 avatar

nick1973

Totally Zenned

Join Date:
Sep 2008
Location:
Cleethorpes
Posts:
1,230
Plugin Contributions:
3

Re: Do stuff on product id

dbltoe:

Starting in 2016 and continuing through 2018, they say use https://... At least that won't cause the mixed content warning on a site.

Thats what i thought i had read. I've been working on structured data this evening though so not had a chance to look again. Structured data is definitely not as easy as it seems and i find googles validation tools can be buggy. Anyway different subject for another time.

Nick Smith - Venture Design and Print
https://venturedesignandprint.co.uk

29 Aug 2019, 11:49 PM
#12
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,845
Plugin Contributions:
17

Re: Do stuff on product id

Yeh, didn't want to muddle the puddle too much. More recent at http://aqualab.cs.northwestern.edu/wp-content/uploads/2019/02/AMP-Mobicom-2019.pdf but, it talks about four different URLs at the top of page 3.
:huh:

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com

30 Aug 2019, 12:03 AM
#13
nick1973 avatar

nick1973

Totally Zenned

Join Date:
Sep 2008
Location:
Cleethorpes
Posts:
1,230
Plugin Contributions:
3

Re: Do stuff on product id

dbltoe:

Yeh, didn't want to muddle the puddle too much. More recent at http://aqualab.cs.northwestern.edu/wp-content/uploads/2019/02/AMP-Mobicom-2019.pdf but, it talks about four different URLs at the top of page 3.
:huh:

Well as far as I know, only two URL's corresponding to the same page or content can exist in google. The other two URL's are referring to the AMP Cache and AMP Viewer. So one None AMP page will exist in the search for Desktop Users or Laptop Users, and the AMP Page will exist in the search on a mobile phone or tablet. However the advantage is the speed of the website in Google terms.

I've worked alot on AMP, Structured Data, and implementing .webp images in Zen Cart these last few weeks. AMP and .webp give a massive advantage on speed and structured data feeds google all the data it requires quicker than reading the whole web page (although it will obviously still crawl it). Add them all together and there are some massive advantages to be had with page rank. But none of them are easy to implement and take a bit of time and patience to say the least. However, if you want to stay ahead then obviously you have take these new technologies on board.

Nick Smith - Venture Design and Print
https://venturedesignandprint.co.uk

30 Aug 2019, 12:09 AM
#14
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,845
Plugin Contributions:
17

Re: Do stuff on product id

My comment to those that don't want to look at the new is, "Clinging tenaciously to the trailing edge of technology.":P

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com

30 Aug 2019, 12:14 AM
#15
nick1973 avatar

nick1973

Totally Zenned

Join Date:
Sep 2008
Location:
Cleethorpes
Posts:
1,230
Plugin Contributions:
3

Re: Do stuff on product id

dbltoe:

My comment to those that don't want to look at the new is, "Clinging tenaciously to the trailing edge of technology.":P

hahaha...yes and end up stuck in a cloud of smog trying desperately to see daylight :D....and then when they do, this happens :jawdrop:

Nick Smith - Venture Design and Print
https://venturedesignandprint.co.uk