Joomla! Discussion Forums



It is currently Sun Nov 22, 2009 3:25 am (All times are UTC )

 


Forum rules

Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.



Post new topic Reply to topic  [ 17 posts ] 
Author Message
Posted: Thu Aug 18, 2005 10:34 pm 
User avatar
Joomla! Intern
Joomla! Intern
Offline

Joined: Thu Aug 18, 2005 10:16 pm
Posts: 73
Location: London, England
I posted this on the other boards, but it went unnoticed with all the uproar! (or just nobody could help..). Hopefully someone here can.. (Please excuse the cut n paste job!)

---------------------------------------------

OK, I've just come across a bit of a problem.

I've included generic accessibility skip links in my template, the usual, skip to content, skip to menu, and top of page stuff. Using the normal top of page sort of thing.

Problem is mambo automatically whacks the root address, i.e. yourcompanyhere.com in front of the hash mark, so those skip links look like, http://www.yourcompanyhere.com/#top. This nullifies the usefulness of these links, as it then always points to the front page, and requires a page reload. Not cool.

I've tried putting these links in as static URLS in a menu but to no avail. Anyone else have this problem, and hopefully a solution?

**************************

Just a thought: If it were possible to add some code to output the current address, either through php or a moscode sort of thing then that could be tacked onto the beginning?

_________________
My mambo sites:
http://www.3tc4u.co.uk
http://changeup.3tc4u.co.uk


Last edited by blue-kiwi on Fri Aug 19, 2005 2:32 pm, edited 1 time in total.

Top
   
 
Posted: Thu Aug 18, 2005 10:41 pm 
Joomla! Ace
Joomla! Ace
Offline

Joined: Thu Aug 18, 2005 9:06 am
Posts: 1465
If you are not 100% sure that Mambo changes the HTML code (using a Mambot for example) then I would claim this is a general issue... the browser makes the link relative to the current path excluding the file.

The following snipped I am using within my TOC:
Code:
$link   = $_SERVER['REQUEST_URI'];
$i   = strpos($link, '#');
if ($i !== FALSE) {
   $link   = substr($link, 0, $i);
}
if ((strlen($link) > strlen($mosConfig_live_site)) && (substr($link, 0, strlen($mosConfig_live_site)) == $mosConfig_live_site)) {
   $link   = substr($link, strlen($mosConfig_live_site) + 1);
}
$link   = sefRelToAbs($link);
$link   .= '#'.$name;


But maybe someone knows another simpler way.

_________________
http://de.siteof.de/


Top
   
 
Posted: Thu Aug 18, 2005 10:46 pm 
User avatar
Joomla! Intern
Joomla! Intern
Offline

Joined: Thu Aug 18, 2005 10:16 pm
Posts: 73
Location: London, England
Thanks for your reply mate! I'm not sure how to check if mambo is changing the code (although I'm failry certain it is), and I have no idea what the code snippet means, or is meant to do, but I appreciate the effort!

_________________
My mambo sites:
http://www.3tc4u.co.uk
http://changeup.3tc4u.co.uk


Top
   
 
Posted: Thu Aug 18, 2005 10:50 pm 
Joomla! Ace
Joomla! Ace
Offline

Joined: Thu Aug 18, 2005 9:06 am
Posts: 1465
blue-kiwi wrote:
Thanks for your reply mate! I'm not sure how to check if mambo is changing the code (although I'm failry certain it is), and I have no idea what the code snippet means, or is meant to do, but I appreciate the effort!

Well, you could just view the page source within your browser and then search for #top to find that link... I am quite sure it is there as you wrote it but when you hover your mouse over the link or even click on it the browser jumps to the page you mention.

As for the code snipped... you asked for some php code... it expects the $name variable to be set to the anchor so "top"... and $link will then in the end contain the absolute URL containing that anchor. I could even tell you the exact steps if you would want to use my component moslate if that is what you want.

_________________
http://de.siteof.de/


Top
   
 
Posted: Thu Aug 18, 2005 10:51 pm 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast
Offline

Joined: Thu Aug 18, 2005 10:24 pm
Posts: 203
Seems to work for me, what version are you using? Are you using SEO?

I did a quick test of this by adding the following to an index.php test:
Code:
<body >
<a name="top"></a>
blech
...
more blech
<a href=#top>return to top</a>
</body>


And on the frontpage the url for return to top is:
http://localhost/index.php#top

And on the license page its:
http://localhost/index.php?option=com_c ... emid=6#top

this is for version 4.5.2

_________________
Randy Carver - carver-family.com

There are 10 types of people in this world.  Those that understand binary and those that don't.


Top
   
 
Posted: Thu Aug 18, 2005 10:58 pm 
User avatar
Joomla! Intern
Joomla! Intern
Offline

Joined: Thu Aug 18, 2005 10:16 pm
Posts: 73
Location: London, England
de wrote:
blue-kiwi wrote:
Thanks for your reply mate! I'm not sure how to check if mambo is changing the code (although I'm failry certain it is), and I have no idea what the code snippet means, or is meant to do, but I appreciate the effort!

Well, you could just view the page source within your browser and then search for #top to find that link... I am quite sure it is there as you wrote it but when you hover your mouse over the link or even click on it the browser jumps to the page you mention.

As for the code snipped... you asked for some php code... it expects the $name variable to be set to the anchor so "top"... and $link will then in the end contain the absolute URL containing that anchor. I could even tell you the exact steps if you would want to use my component moslate if that is what you want.


That looks good mate, a step by step idots guide would be much appreciated! Have you already wrapped this up in a mambot/component or something? What is moslate?

The site in question is http://www.3tc4u.co.uk, if you look at the source the links look like top, correlating to , yet on any page mambo is putting the root address in front of it. I tried both in IE and Firefox, and get the same thing...

_________________
My mambo sites:
http://www.3tc4u.co.uk
http://changeup.3tc4u.co.uk


Top
   
 
Posted: Thu Aug 18, 2005 11:15 pm 
Joomla! Ace
Joomla! Ace
Offline

Joined: Thu Aug 18, 2005 9:06 am
Posts: 1465
Ok, partially what I said was incorrect... I just knew I had a problem and now I know again where it actually comes from... you will find in your page source that is what makes all links relative to the home. I would not remove that though, as it is a good thing in some means (for example relative css/image references)...

However, the step by step guide comes here (but as said I don't know whether there is a simpler way)... ahh just realize this is inside your template right? (then forget about my component)
In your template write in the beginning (somewhere between ):
Code:
function getRelativeAnchorLink($name) {
  global $mosConfig_live_site;
  $link   = $_SERVER['REQUEST_URI'];
  $i   = strpos($link, '#');
  if ($i !== FALSE) {
   $link   = substr($link, 0, $i);
  }
  if ((strlen($link) > strlen($mosConfig_live_site)) && (substr($link, 0, strlen($mosConfig_live_site)) == $mosConfig_live_site)) {
   $link   = substr($link, strlen($mosConfig_live_site) + 1);
  }
  if ((strlen($link) > 0) && (substr($link, 0, 1) == '/')) {
   $link   = substr($link, 1);
  }
  $link   = sefRelToAbs($link);
  $link   .= '#'.$name;
  return $link;
}


And then whereever you want to use it within your template write something like this:
Code:
<a href="<?php echo getRelativeAnchorLink('top'); ?>">top of page</a>

_________________
http://de.siteof.de/


Last edited by de on Wed Nov 16, 2005 7:33 pm, edited 1 time in total.

Top
   
 
Posted: Thu Aug 18, 2005 11:17 pm 
User avatar
Joomla! Intern
Joomla! Intern
Offline

Joined: Thu Aug 18, 2005 10:16 pm
Posts: 73
Location: London, England
Excellent, give me a min to try it out, will report back! :)

_________________
My mambo sites:
http://www.3tc4u.co.uk
http://changeup.3tc4u.co.uk


Top
   
 
Posted: Thu Aug 18, 2005 11:21 pm 
Joomla! Ace
Joomla! Ace
Offline

Joined: Thu Aug 18, 2005 9:06 am
Posts: 1465
I forgot the "global $mosConfig_live_site;" in the beginning of the function (changed my previous post).

_________________
http://de.siteof.de/


Top
   
 
Posted: Thu Aug 18, 2005 11:27 pm 
Sweeeeet :)  I'll have to implement that when I have a moment.  Couple of my sites "puke out" with local anchors.


Top
   
 
Posted: Fri Aug 19, 2005 1:28 pm 
User avatar
Joomla! Intern
Joomla! Intern
Offline

Joined: Thu Aug 18, 2005 10:16 pm
Posts: 73
Location: London, England
This is excellent!! Thank you so much for your time and skill de.. I have a few sites that need this and I'm putting them in now! If I could give you reputation or good karma on these boards rest assured I would! Thanks a lot,

kiwi

_________________
My mambo sites:
http://www.3tc4u.co.uk
http://changeup.3tc4u.co.uk


Top
   
 
Posted: Tue Jan 10, 2006 1:57 pm 
User avatar
Joomla! Hero
Joomla! Hero
Offline

Joined: Thu Aug 18, 2005 4:35 pm
Posts: 2838
Location: Cheshire, England
Aahhh - after an age searching, I find the answer. Thanks de.

Is this not considered a bug? surely basic anchors should work with SEF?

_________________
Look at the page source... Lots of useful info...


Last edited by toubkal on Tue Jan 10, 2006 2:15 pm, edited 1 time in total.

Top
   
 
Posted: Tue Jan 10, 2006 9:44 pm 
toubkal, when I discussed this with MasterChief a few weeks back, he was flabbergasted.  Said things "should" work properly.  And sure enough, tried it, it works...

Hmmm.

//Edit: FWIW, mosconfig_whatever doesn't exist in 1.1 anymore...  Still left as legacy stuff, so it should work, but it's not native anymore :)


Top
   
 
Posted: Tue Jan 10, 2006 9:55 pm 
Joomla! Ace
Joomla! Ace
Offline

Joined: Thu Aug 18, 2005 9:06 am
Posts: 1465
vavroom wrote:
toubkal, when I discussed this with MasterChief a few weeks back, he was flabbergasted.  Said things "should" work properly.  And sure enough, tried it, it works...

With SEF turned on (SEF URL contains a new sub directory compared to the base), a proper base URL set for the document and not inside an content item (where a Mambot could grab it)? Not tested now by myself... but I think that are the "error conditions".

(Side note: added "flabbergasted" to the list of known words)

_________________
http://de.siteof.de/


Top
   
 
Posted: Tue Jan 10, 2006 10:02 pm 
User avatar
Joomla! Hero
Joomla! Hero
Offline

Joined: Thu Aug 18, 2005 4:35 pm
Posts: 2838
Location: Cheshire, England
I am actually tring to use an anchor in the template, not within content. This is for a "skip to main content" link for accessability (and it helps with usability on for e.g. mobile phones)

should I be doing something different to make it work in the template?

the code I originally tried was:

Code:
<a href="#maincontent" class="skip">Skip to main content</a>


and .....


<a name="maincontent" id="maincontent"></a>

_________________
Look at the page source... Lots of useful info...


Top
   
 
Posted: Wed Mar 29, 2006 1:11 pm 
User avatar
Joomla! Fledgling
Joomla! Fledgling
Offline

Joined: Wed Mar 29, 2006 12:43 pm
Posts: 3
Location: Paris
Had some problems to make the code above work with openSEF (on 1.0.7).

Here's another option :

function getRelativeAnchorLink($name) {
global $mosConfig_live_site;

if ($_SERVER['QUERY_STRING']) $link = sefRelToAbs( "index.php?" . str_replace("&", "&", $_SERVER['QUERY_STRING'] ) );
else $link = $mosConfig_live_site . "/";
$link .= '#'.$name;
return $link;

}

It work with openSEF, partially tested with standard joomla SEF, seems ok

_________________
55 Thinking - Strategy Design Technology 
Good looking, Fast and Usable web solutions   
http://www.55thinking.com/


Top
   
 
Posted: Sun Jan 07, 2007 10:58 am 
Joomla! Fledgling
Joomla! Fledgling
Offline

Joined: Sun Sep 03, 2006 9:38 pm
Posts: 2
de wrote:
Ok, partially what I said was incorrect... I just knew I had a problem and now I know again where it actually comes from... you will find in your page source that is what makes all links relative to the home. I would not remove that though, as it is a good thing in some means (for example relative css/image references)...

However, the step by step guide comes here (but as said I don't know whether there is a simpler way)... ahh just realize this is inside your template right? (then forget about my component)
In your template write in the beginning (somewhere between ):
Code:
function getRelativeAnchorLink($name) {
  global $mosConfig_live_site;
  $link   = $_SERVER['REQUEST_URI'];
  $i   = strpos($link, '#');
  if ($i !== FALSE) {
   $link   = substr($link, 0, $i);
  }
  if ((strlen($link) > strlen($mosConfig_live_site)) && (substr($link, 0, strlen($mosConfig_live_site)) == $mosConfig_live_site)) {
   $link   = substr($link, strlen($mosConfig_live_site) + 1);
  }
  if ((strlen($link) > 0) && (substr($link, 0, 1) == '/')) {
   $link   = substr($link, 1);
  }
  $link   = sefRelToAbs($link);
  $link   .= '#'.$name;
  return $link;
}


And then whereever you want to use it within your template write something like this:
Code:
<a href="<?php echo getRelativeAnchorLink('top'); ?>">top of page</a>



you're my hero as well :)
thanx a lot for this fix!


Top
  E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ] 

Quick reply

 



Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group