Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Calling the current product page url with php

Calling the current product page url with php

Views: 4,101

Results 1 to 20 of 25
30 Nov 2011, 8:29 PM
#1
pricediscrimination avatar

pricediscrimination

Zen Follower

Join Date:
May 2008
Posts:
401
Plugin Contributions:
0

Calling the current product page url with php

How can you use php to call the current product page's url and use it within a link?

for example to do something like this:

<a href="<?php CURRENT PAGE ?>">clicky</a>

1 Dec 2011, 2:26 AM
#2
gaurav10feb avatar

gaurav10feb

Zen Follower

Join Date:
Jan 2010
Location:
Australia
Posts:
243
Plugin Contributions:
1

Re: Calling the current product page url with php

<?php echo $_SERVER['HTTP_HOST'] .$_SERVER['REQUEST_URI']; ?>
1 Dec 2011, 4:21 PM
#3
pricediscrimination avatar

pricediscrimination

Zen Follower

Join Date:
May 2008
Posts:
401
Plugin Contributions:
0

Re: Calling the current product page url with php

gaurav10feb:

<?php echo $_SERVER['HTTP_HOST'] .$_SERVER['REQUEST_URI']; ?>

Thanks!

I had to change it to <?php echo $_SERVER['REQUEST_URI']; ?> to get it to work because it was pulling up the root url twice then like http://site.comhttp://site.comhttp://site.com/product/category/blah

Is this a standard php call? I always though zencart had a way of doing it too, like zen_url something something.

2 Dec 2011, 1:51 AM
#4
swguy avatar

swguy

Administrator

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

Re: Calling the current product page url with php

The function within the Zen Cart infrastructure is called zen_href_link.

If the product you're looking at is 5, for example, you would use

<a href="<?php echo zen_href_link(zen_get_info_page(5), "&products_id=5"); ?>">Some anchor text</a>

If you're on the product info page and you want the product id you're looking at, it's in

(int)$_GET['products_id']

(but if you're on the product page for a specific product, why do you need another URL to the product page for that product?)

2 Dec 2011, 4:08 AM
#5
pricediscrimination avatar

pricediscrimination

Zen Follower

Join Date:
May 2008
Posts:
401
Plugin Contributions:
0

Re: Calling the current product page url with php

swguy:

(but if you're on the product page for a specific product, why do you need another URL to the product page for that product?)

If you are linking to a div located lower down on the page.

2 Dec 2011, 6:25 AM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Calling the current product page url with php

So is your real question actually about how to properly create a named anchor link within a page? There are numerous threads on that topic.

2 Dec 2011, 11:19 AM
#7
swguy avatar

swguy

Administrator

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

Re: Calling the current product page url with php

... and indeed, such a link should not use the current page information.

Read <a href="#more">more here</a> ...

...

<a name="more"></a>
Here's more ....

2 Dec 2011, 3:57 PM
#8
pricediscrimination avatar

pricediscrimination

Zen Follower

Join Date:
May 2008
Posts:
401
Plugin Contributions:
0

Re: Calling the current product page url with php

swguy:

... and indeed, such a link should not use the current page information.

Read <a href="#more">more here</a> ...

...

<a name="more"></a>
Here's more ....

But it works using the php you provided above.

2 Dec 2011, 3:58 PM
#9
swguy avatar

swguy

Administrator

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

Re: Calling the current product page url with php

I know that it works, but you're going back to the server for another page throw when you don't need to. The last way I suggested will be faster since it happens entirely in the browser.

2 Dec 2011, 4:00 PM
#10
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Calling the current product page url with php

Just because it can work doesn't mean it's the best way to do it. The full URL would break if you made a test copy of your site elsewhere. The name anchor link would still work fine.

2 Dec 2011, 4:08 PM
#11
pricediscrimination avatar

pricediscrimination

Zen Follower

Join Date:
May 2008
Posts:
401
Plugin Contributions:
0

Re: Calling the current product page url with php

DrByte:

So is your real question actually about how to properly create a named anchor link within a page? There are numerous threads on that topic.

Found this thread but it seems that would only work on a static page, not on a product page right? Using the code above it pulls whatever the product page URL is and adds the div tag (anchor) to the end so that no matter how many different product pages you make it will always pull that page's url.

3 Dec 2011, 1:36 AM
#12
usernamenone avatar

usernamenone

Totally Zenned

Join Date:
Sep 2006
Posts:
541
Plugin Contributions:
0

Re: Calling the current product page url with php

<a href="<?php echo $_SERVER['PHP_SELF']; ?>" class="links">Text Here </a>

3 Dec 2011, 3:45 AM
#13
pricediscrimination avatar

pricediscrimination

Zen Follower

Join Date:
May 2008
Posts:
401
Plugin Contributions:
0

Re: Calling the current product page url with php

usernamenone:

<a href="<?php echo $_SERVER['PHP_SELF']; ?>" class="links">Text Here </a>

Thanks. What's the difference between that and this? <?php echo $_SERVER['HTTP_HOST'] .$_SERVER['REQUEST_URI']; ?>

15 Dec 2011, 4:53 PM
#15
skidude avatar

skidude

New Zenner

Join Date:
Dec 2011
Posts:
7
Plugin Contributions:
0

Re: Calling the current product page url with php

swguy:

... and indeed, such a link should not use the current page information.

Read <a href="#more">more here</a> ...

...

<a name="more"></a>
Here's more ....

I want to use anchor tags to let users jump to a different section of a long product page. This simple html isn't working on my page. It tries to jump to "http://mysite.com/#more" instead of "http://mysite.com/index.php?main_page=product_info&cPath=1&products_id=15/#more"

What am I doing wrong?

15 Dec 2011, 8:41 PM
#16
usernamenone avatar

usernamenone

Totally Zenned

Join Date:
Sep 2006
Posts:
541
Plugin Contributions:
0

Re: Calling the current product page url with php

<a name="anchor1">to anchor1 Section</a>

<a href="#anchor1">Visit the anchor1 Section</a>

You will need to determine your placements

15 Dec 2011, 9:15 PM
#17
skidude avatar

skidude

New Zenner

Join Date:
Dec 2011
Posts:
7
Plugin Contributions:
0

Re: Calling the current product page url with php

usernamenone:

<a name="anchor1">to anchor1 Section</a>

<a href="#anchor1">Visit the anchor1 Section</a>

You will need to determine your placements

That should work. It works on regular HTML pages.

I've tried it and it didn't work with a zencart PRODUCT.

It brings me to "http://mysite.com/#anchor1"

It does not go to
"http://mysite.com/index.php?main_page=product_info&cPath=1&products_id=15/#anchor1"

Do I really need to code it like this?

<a href="mysite.com/index.php?main_page=product_info&cPath=1&products_id=15/#anchor1">Visit the anchor1 Section</a>

<a name="anchor1">to anchor1 Section</a>

15 Dec 2011, 10:41 PM
#18
usernamenone avatar

usernamenone

Totally Zenned

Join Date:
Sep 2006
Posts:
541
Plugin Contributions:
0

Re: Calling the current product page url with php

skidude:

I want to use anchor tags to let users jump to a different section of a long product page. This simple html isn't working on my page. It tries to jump to "http://mysite.com/#more" instead of "http://mysite.com/index.php?main_page=product_info&cPath=1&products_id=15/#more"

What am I doing wrong?

You don't need php for the code. You add your product description in admin within the description you are using html not php.

That script works and if you can not get it to then you are not using it in the right manor.

<a name="anchor1">to anchor1 Section</a>And here is long text that goes down the page, bla bla bla

and this is the anchor that goes back to anchor1
<a href="#anchor1">Visit the anchor1 Section</a>

And if this is not what you want to do then you need to explain it in a different manor

16 Dec 2011, 2:08 AM
#19
skidude avatar

skidude

New Zenner

Join Date:
Dec 2011
Posts:
7
Plugin Contributions:
0

Re: Calling the current product page url with php

Thanks for the help.

What script are you referring to? Do you mean the href call?

I copied your href code and put it in the product description.

I think that I must be missing something that is very obvious.

Here are two screen shots. One is the product creation and the other is it displayed.

=========================================

Notice it doesn't want to link to "http://mysite.com/zen2/index.php?main_page=product_info&cPath=1&products_id=1#anchor1"

16 Dec 2011, 2:52 AM
#20
usernamenone avatar

usernamenone

Totally Zenned

Join Date:
Sep 2006
Posts:
541
Plugin Contributions:
0

Re: Calling the current product page url with php

So then you have to ask yourself what other files you have messed with? without a link to your site I can't guess.