Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Creating a 'Page Top' link / anchor

Creating a 'Page Top' link / anchor

Locked

Views: 6,436

Results 1 to 17 of 17
This thread is locked. New replies are disabled.
30 Nov 2006, 7:34 AM
#1
website_rob avatar

website_rob

Inactive

Join Date:
Oct 2006
Location:
Alberta, Canada
Posts:
4,572
Plugin Contributions:
0

Creating a 'Page Top' link / anchor

Would like to create a link at the bottom of each page for "Page Top". As the script puls in URLs from various places, the normal HTML code will not work -- other than on the Home page. Once you go into a Catagory and start getting product IDs added, it gets a bit tricky.

<a href="' . $_GET['main_page'] . '#ptop" title="Go to top of this Page">Page Top</a>

Just focusing on the code required within the '<a /a>' the above is what I have so far. My coding is not up to snuff enough to know which coding is required, to pull in the rest of the required URL.

Can anyone point me in the right direction for the rest of the code needed?

30 Nov 2006, 9:19 AM
#2
samad64 avatar

samad64

Totally Zenned

Join Date:
May 2006
Location:
Texas
Posts:
554
Plugin Contributions:
2

Re: Creating a 'Page Top' link / anchor

if you wanted to.. you could just put this:

<a href="#ptop" title="Go to top of this Page">Page Top</a>  

and it should work, assuming you have an anchor at the top of the page (like in the header). it should automatically tag the url you're at with the #ptop

so.. if you're at mydomain.com/index.php ... it will show mydomain.com/index.php#ptop

if you're at mydomain.com/index.php?main_page=shippinginfo , it will show mydomain.com/index.php?main_page=shippinginfo#ptop

30 Nov 2006, 9:57 AM
#3
website_rob avatar

website_rob

Inactive

Join Date:
Oct 2006
Location:
Alberta, Canada
Posts:
4,572
Plugin Contributions:
0

Re: Creating a 'Page Top' link / anchor

One would think that but not so.

1 Dec 2006, 2:41 PM
#4
website_rob avatar

website_rob

Inactive

Join Date:
Oct 2006
Location:
Alberta, Canada
Posts:
4,572
Plugin Contributions:
0

Re: Creating a 'Page Top' link / anchor

Actually, to correct my last post, the 'id' tag does work for basic pages such as described. The problem comes in when you are in a Catagory and/or on a specific Product page.

Once 'product_info' or 'cPath' gets put into the URL, the 'page top' link no longer works.

1 Dec 2006, 3:00 PM
#5
tkroh avatar

tkroh

New Zenner

Join Date:
Sep 2006
Location:
San Antonio, TX, USA
Posts:
32
Plugin Contributions:
0

Re: Creating a 'Page Top' link / anchor

getyourgameshere.com:

...assuming you have an anchor at the top of the page (like in the header).> Website Rob:

One would think that but not so.
Is that assumption correct?

2 Dec 2006, 9:57 PM
#6
website_rob avatar

website_rob

Inactive

Join Date:
Oct 2006
Location:
Alberta, Canada
Posts:
4,572
Plugin Contributions:
0

Re: Creating a 'Page Top' link / anchor

Yes. This was confirmed earlier, "the 'id' tag does work for basic pages".

2 Dec 2006, 10:13 PM
#7
paulm avatar

paulm

Totally Zenned

Join Date:
Nov 2003
Posts:
1,878
Plugin Contributions:
5

Re: Creating a 'Page Top' link / anchor

A way it really* works for me on a "similar to Zen Cart site" is:```
<a href="<?php echo $_SERVER['REQUEST_URI']; ?>#top">Top</a>


(*really => without reloading the page when clicking the link)
2 Dec 2006, 10:16 PM
#8
paulm avatar

paulm

Totally Zenned

Join Date:
Nov 2003
Posts:
1,878
Plugin Contributions:
5

Re: Creating a 'Page Top' link / anchor

And now that I think of it, this looks like it invokes a security problem :shocking:
Doesn't it?

4 Dec 2006, 9:33 AM
#9
website_rob avatar

website_rob

Inactive

Join Date:
Oct 2006
Location:
Alberta, Canada
Posts:
4,572
Plugin Contributions:
0

Re: Creating a 'Page Top' link / anchor

As it is only an 'echo' statement I do not see much of a security breach, that any other page would not have as well.

Also, thank you for posting, Paul. Your code solved my problem.

4 Dec 2006, 10:20 AM
#10
paulm avatar

paulm

Totally Zenned

Join Date:
Nov 2003
Posts:
1,878
Plugin Contributions:
5

Re: Creating a 'Page Top' link / anchor

Hi Rob,

glad to hear that it works for you too :-)
(I guess relative url's by default are not made to work with query strings, which seems more or less logical)

The security issue I was thinking of is that $_SERVER['REQUEST_URI'] contains the query string, and the query string is user input. And, if echoed back, I would think this allows cross site scripting attacks.

So I think it's better to use:

<a href="<?php echo zen_output_string_protected($_SERVER['REQUEST_URI']); ?>#top">Top</a>
4 Dec 2006, 9:13 PM
#11
tkroh avatar

tkroh

New Zenner

Join Date:
Sep 2006
Location:
San Antonio, TX, USA
Posts:
32
Plugin Contributions:
0

Re: Creating a 'Page Top' link / anchor

Oh, I see what your issue is/was. Another solution for you would be to add an image/button/link that says "Top" with an onclick event that takes you to the top of the page--no server-side voodoo required.

<img src="Top.png" alt="Top" onclick="document.body.scrollTop=0;" />
13 Mar 2007, 5:44 PM
#12
slabadoo avatar

slabadoo

Zen Follower

Join Date:
Jan 2007
Posts:
149
Plugin Contributions:
1

Re: Creating a 'Page Top' link / anchor

Hate to open this one back up but the thread is still unanswered if you are in a category. The link tothe anchor still goes to the main page and still refreshes it. Or of course I am still doing it wrong. Is there anyone out there that has made the anchor work with refreshing but going to the top?

Thanks,
Rick

15 Mar 2007, 11:42 AM
#13
website_rob avatar

website_rob

Inactive

Join Date:
Oct 2006
Location:
Alberta, Canada
Posts:
4,572
Plugin Contributions:
0

Re: Creating a 'Page Top' link / anchor

I guess what makes it confusing is that 3 files have to be changed:

  1. includes/templates/custom/common/tpl_footer-pagetop_link.php
  2. includes/templates/custom/common/tpl_footer.php
  3. includes/templates/custom/common/tpl_main_page.php

Use the code provided by Paul on page 1 of this thread, for the first 2 pages. The 3rd page, is your other half of the link and uses:

<body id="<?php echo $body_id . 'Body'; ?>"<?php if($zv_onload !='') echo ' onload="'.$zv_onload.'"'; ?>>

[B]<div><a id="top"></a></div>[/B]

Working example: http://reelstackle.com/

7 Dec 2008, 10:33 AM
#14
shocker avatar

shocker

Zen Follower

Join Date:
Jul 2007
Location:
Jakarta
Posts:
346
Plugin Contributions:
0

Re: Creating a 'Page Top' link / anchor

I've tried using the following example from paulm to place a ^top^ link at the bottom of my define_shipping.php page.

But it doesn't work. Am I missing something? I also have anchor tags on this page that I want to use, but I can't seem to get it working without reloading the whole page.

paulm:

Hi Rob,

So I think it's better to use:

<a href="<?php echo zen_output_string_protected($_SERVER['REQUEST_URI']); ?>#top">Top</a>

8 Dec 2008, 10:10 AM
#15
website_rob avatar

website_rob

Inactive

Join Date:
Oct 2006
Location:
Alberta, Canada
Posts:
4,572
Plugin Contributions:
0

Re: Creating a 'Page Top' link / anchor

Did you apply changes to the 3 files mentioned in the post above yours?

9 Dec 2008, 12:59 PM
#16
shocker avatar

shocker

Zen Follower

Join Date:
Jul 2007
Location:
Jakarta
Posts:
346
Plugin Contributions:
0

Re: Creating a 'Page Top' link / anchor

Website Rob:

Did you apply changes to the 3 files mentioned in the post above yours?

I got this working:smile:, but one of the things I want to do is have links on my shipping_info page to anchor link locations on the same page.

See: http://www.nahidfashions.com/boutique/shippinginfo.html

I have this setup, but the page completely reloads. This shouldn't be necessary.:blink:
Is there a similar tag for in-page anchors like the "top" anchor?

19 Mar 2009, 4:49 AM
#17
shocker avatar

shocker

Zen Follower

Join Date:
Jul 2007
Location:
Jakarta
Posts:
346
Plugin Contributions:
0

Re: Creating a 'Page Top' link / anchor

How can apply this to other in-page links?
Adding more div's in the tpl_main_page.php doesn't seem practical every time I want a new in-page link.