Recent Topics

Jump to top of page function

Started by on Sep 06, 2005 – Contents updated: Sep 06, 2005

Sep 06, 2005 02:37    

Is it possible to have a link that would jump you to the top of your blog? Something like the bookmark function in Frontpage. That would be handy for blogs with long posts and pictures that take up a lot of space.

Sep 06, 2005 05:57

I would think you could add this into a skin pretty easily. Just edit _main.php and add this right after the <body> tag:

<a name="top"></a>


Then, wherever you want it to appear, put:

<a href="#top">Jump to top</a>


The most natural place to put it would be right before or after the comment link and date that follow each post. You could put it at the very bottom of the page, too. I haven't tested this, but I don't know why it wouldn't work.

Sep 06, 2005 06:23

I tried your suggestion, but when I click on the link, I'm directed to a directory page titled "Index of /blog/skins/MT_dot_org" listing all the pages and images in that root. But thanks for sharing your thought.

Sep 06, 2005 06:42

The problem is because "<a href="#top">Jump to top</a>" is a relative link and b2evolution uses the base tag for skin-related stuff. To make it work you would have to come up with the complete url of the page the visitor is on. It could be your blog's main page, but it could also be the second or third (or more!) page of multiple posts.

Unfortunately I don't have a solution. Hopefully someone will come along and say how easy it is to make it be "<a href="THE_URL_OF_THE_CURRENT_PAGE#top">Jump to top</a>".

BTW I'm moving this to the "Request a Plugin or Hack" forum because that's what this is.

EDIT: It would make a nice hack. I hope someone figures it out, and posts the solution in the plugins and hacks forum

Sep 06, 2005 16:24

This works with mine

File name: /skins/skinname/_main.php

Put this where you want the jump to go to:

<a name="top"/>

Put this where you want the jump link:

<?php
$url = sprintf("%s%s%s","http://",$HTTP_HOST,$REQUEST_URI); 
?>

 <a href="<?php echo $url ?>#top">Jump to top</a>

Thats all there should be to it

Jon

Sep 06, 2005 17:51

Works like a charm! :D Thanks Jon!

Sep 06, 2005 18:14

jinbrother1 wrote:

Works like a charm! :D Thanks Jon!

Glad to hear it.

Jon

Sep 06, 2005 18:14

Thank you :) , sure beats using

<a href="<?php echo regenerate_url() ?>#top" title="goto page top">top</a>

Sep 06, 2005 20:21

Both of these solutions look great. Can anyone explain to me why one would be better than the other?

Sep 06, 2005 22:57

personman wrote:

Both of these solutions look great. Can anyone explain to me why one would be better than the other?

On my Blog this code:


<?php $jumpurl = sprintf("%s%s%s","http://",$HTTP_HOST,$REQUEST_URI);?>

Produces this for the URL:

http://projects.urjb.com/index.php/Lego/2005/08/21/harddrive_case#top

This code:

<a href="<?php echo regenerate_url() ?>#top" title="goto page top">top</a>

Produces a URL of :

http://projects.urjb.com/index.php/Lego/2005/08/21/harddrive_case?blog=3&c=1&page=1&more=1&title=harddrive_case&tb=1&pb=1&disp=single#top

For me, I like the cleaner looking URL.

Also the regenerate sends a query to the server when you click the link, where as the $var does not. At least on the browsers I checked it with FF and IE

Just my 38 cents Gas prices went up :p

Jon

Sep 06, 2005 23:00

I see. That is better. Thanks for explaining it.

Sep 06, 2005 23:46

If you want to save a CPU cycle or 2

push it back on the client with Javascript


<script language="JavaScript" type="text/javascript">
<!--
document.write("<a href= \"" + document.location + "#top\">Jump Up</a>");
// -->
</script>

But that would be so 1999 ;)

Jon

Sep 07, 2005 01:50

I guess it should be noted that

this function

sprintf("%s%s%s","http://",$HTTP_HOST,$REQUEST_URI)

pulls what is shown in the browsers address bar.

and this

regenerate_url()

Generates the full [u]URI[/u] of the page.

So the bottom line is, if the Use extra-path info: checkbox in the back office is not checked, they will both act the same.

Or you could always just use the scrollbar :>

Jon


Form is loading...

Photo gallery software – This forum is powered by b2evolution CMS, a complete engine for your website.