Page 1 of 3 123 LastLast
Results 1 to 10 of 25
  1. #1
    Join Date
    May 2008
    Posts
    402
    Plugin Contributions
    0

    Default 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>

  2. #2
    Join Date
    Jan 2010
    Location
    Australia
    Posts
    239
    Plugin Contributions
    1

    Default Re: Calling the current product page url with php

    <?php echo $_SERVER['HTTP_HOST'] .$_SERVER['REQUEST_URI']; ?>
    Believe it or not But My existence is illusional

  3. #3
    Join Date
    May 2008
    Posts
    402
    Plugin Contributions
    0

    Default Re: Calling the current product page url with php

    Quote Originally Posted by gaurav10feb View Post
    <?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:/.../category/blah

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

  4. #4
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,696
    Plugin Contributions
    123

    Default 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?)
    That Software Guy. My Store: Zen Cart Modifications
    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.

  5. #5
    Join Date
    May 2008
    Posts
    402
    Plugin Contributions
    0

    Default Re: Calling the current product page url with php

    Quote Originally Posted by swguy View Post
    (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.

  6. #6
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default 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.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  7. #7
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,696
    Plugin Contributions
    123

    Default 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 ....
    That Software Guy. My Store: Zen Cart Modifications
    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.

  8. #8
    Join Date
    May 2008
    Posts
    402
    Plugin Contributions
    0

    Default Re: Calling the current product page url with php

    Quote Originally Posted by swguy View Post
    ... 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.

  9. #9
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,696
    Plugin Contributions
    123

    Default 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.
    That Software Guy. My Store: Zen Cart Modifications
    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.

  10. #10
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default 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.

 

 
Page 1 of 3 123 LastLast

Similar Threads

  1. v151 with ultimate seo Url,how to change the ez-page url ?
    By whywell in forum General Questions
    Replies: 1
    Last Post: 17 Jan 2013, 09:12 AM
  2. v150 what is the php code to return the url of the current page?
    By WebKat in forum General Questions
    Replies: 7
    Last Post: 8 Mar 2012, 11:24 PM
  3. how to get the value of current category with PHP code?
    By mybiz9999 in forum All Other Contributions/Addons
    Replies: 5
    Last Post: 16 Feb 2011, 05:27 PM
  4. Highlight the Current Page with CSS
    By FoodDudes in forum Templates, Stylesheets, Page Layout
    Replies: 12
    Last Post: 28 Feb 2010, 01:13 AM
  5. Replies: 1
    Last Post: 22 Mar 2007, 05:37 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR