How do I link to an Anchor in an article?
Moderator: Thorsten
-
- Posts: 61
- Joined: Tue Mar 27, 2007 8:57 pm
- Location: Palo Alto, California
- Contact:
How do I link to an Anchor in an article?
I want to link to a specific subsection of an article. How do I do this? The normal html anchor doesn't seem to work.
The TinyMCE editor allows me to create an anchor tag in my article content. E.g. <a name="options" title="options"></a>
The editor also provides a way to link to the anchor, generating code like this:
<a href="/#options">Options</a>
But the link resulting on the article page fails, since it's trying to link to "/#options". (I've removed the leading "/" in the href but to no avail).
I've tried adding &anchor=options to the query string (e.g. index.php?action=artikel&cat=4&id=23&artlang=en&anchor=options) but that doesn't do anything.
The TinyMCE editor allows me to create an anchor tag in my article content. E.g. <a name="options" title="options"></a>
The editor also provides a way to link to the anchor, generating code like this:
<a href="/#options">Options</a>
But the link resulting on the article page fails, since it's trying to link to "/#options". (I've removed the leading "/" in the href but to no avail).
I've tried adding &anchor=options to the query string (e.g. index.php?action=artikel&cat=4&id=23&artlang=en&anchor=options) but that doesn't do anything.
Hi,
isn't it working in HTML mode?
bye
Thorsten
isn't it working in HTML mode?
bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
amazon.de Wishlist
-
- Posts: 61
- Joined: Tue Mar 27, 2007 8:57 pm
- Location: Palo Alto, California
- Contact:
No, it doesn't work because the anchor resolves as /index.php#anchor, which of course, doesn't exist. The anchor is part of the article. Try this simple test and let me know if it works for you:
Create a new article, call it "anchor test".
Paste this code into the HTML window of the article -
<p><a href="#anchor">Link</a></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p><a name="anchor" id="anchor"></a>anchor </p>
Save the article.
View the article in the user interface.
Click the Link.
If the page scrolls to the anchor, then something's wrong with my installation. If you get a Forbidden message, then you are seeing what I see.
(The code above works fine in a normal html page)
Create a new article, call it "anchor test".
Paste this code into the HTML window of the article -
<p><a href="#anchor">Link</a></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p><a name="anchor" id="anchor"></a>anchor </p>
Save the article.
View the article in the user interface.
Click the Link.
If the page scrolls to the anchor, then something's wrong with my installation. If you get a Forbidden message, then you are seeing what I see.
(The code above works fine in a normal html page)
Hi,
right... it's not working... you need the full path there... maybe I should implement an interface for this...
bye
Thorsten
right... it's not working... you need the full path there... maybe I should implement an interface for this...
bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
amazon.de Wishlist
-
- Posts: 61
- Joined: Tue Mar 27, 2007 8:57 pm
- Location: Palo Alto, California
- Contact:
Oh! I see now. I had been trying index.php#anchor?... but I realize the anchor can be appended to the end of the query string, like this:
index.php?action=artikel&cat=1&id=28&artlang=en#anchor
I had no idea that was legal syntax.
UI for this would be nice. Or at least, documentation.
Thanks for the help.
Rick
index.php?action=artikel&cat=1&id=28&artlang=en#anchor
I had no idea that was legal syntax.
UI for this would be nice. Or at least, documentation.
Thanks for the help.
Rick
Re: How do I link to an Anchor in an article?
I managed to do anchors with anchor tool. That way all links to same article are working nicely - until I update the article. After that all anchors lost their path to article. See links from user interface source:
After creating an anchor: /phpmyfaq/index.php?action=artikel&lang=fi&id=9#anchor
After updating the acticle again: /#anchor
And now, obviously, the right article cannot be shown.
I done a little search through the code and found something. On /artikle.php there is this line:
$content = str_replace('href="/#','href="index.php?action=artikel&lang='.$LANGCODE.'&id='.$id.'#', $fixedContent);
If I write die($content); after that, I get links right (url is /phpmyfaq/index.php?action=artikel&lang=fi&id=9#anchor). Links remain right even if I call die() and display $content in the very last line of the file. But when links are displayed in user interface they are broken.
Am I doing some mistake or does someone else have this kind of error also?
After creating an anchor: /phpmyfaq/index.php?action=artikel&lang=fi&id=9#anchor
After updating the acticle again: /#anchor
And now, obviously, the right article cannot be shown.
I done a little search through the code and found something. On /artikle.php there is this line:
$content = str_replace('href="/#','href="index.php?action=artikel&lang='.$LANGCODE.'&id='.$id.'#', $fixedContent);
If I write die($content); after that, I get links right (url is /phpmyfaq/index.php?action=artikel&lang=fi&id=9#anchor). Links remain right even if I call die() and display $content in the very last line of the file. But when links are displayed in user interface they are broken.
Am I doing some mistake or does someone else have this kind of error also?
Re: How do I link to an Anchor in an article?
Hi,
it seems there's a bug in the editor component. I'll try to implement a patch.
bye
Thorsten
it seems there's a bug in the editor component. I'll try to implement a patch.
bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
amazon.de Wishlist
Re: How do I link to an Anchor in an article?
I still can't create anchors that would stay after updating... Have you found anything to fix this? Anyway, thanks for your concern, Thorsten! (:
Edit June 30, 2009:
I've done a little search... Anchor thing was a bug in TinyMCE before version 3 or so. I downloaded phpMyFAQ RC2 and tested it. Now the editor doesn't add any slashes before the anchor. Though, anchors didn't work before I altered /artikel.php a bit on line 138.
Find this:
Replace with this:
So now slahs in the search string!
Edit June 30, 2009:
I've done a little search... Anchor thing was a bug in TinyMCE before version 3 or so. I downloaded phpMyFAQ RC2 and tested it. Now the editor doesn't add any slashes before the anchor. Though, anchors didn't work before I altered /artikel.php a bit on line 138.
Find this:
Code: Select all
$content = str_replace('href="/#','href="index.php?action=artikel&lang='.$LANGCODE.'&id='.$record_id.'#', $fixedContent);
Code: Select all
$content = str_replace('href="#','href="index.php?action=artikel&lang='.$LANGCODE.'&id='.$record_id.'#', $fixedContent);
Re: How do I link to an Anchor in an article?
Hi,
is this fix for version 2.5?
bye
Thorsten
is this fix for version 2.5?
bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
amazon.de Wishlist
Re: How do I link to an Anchor in an article?
Yes, it is.
Re: How do I link to an Anchor in an article?
Hi,
thanks, it's fixed in SVN for the RC3 release.
bye
Thorsten
thanks, it's fixed in SVN for the RC3 release.
bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
amazon.de Wishlist
Re: How do I link to an Anchor in an article?
Thanks a lot, Thorsten! (:
Re: How do I link to an Anchor in an article?
Hi Thorsten,
I believe the above fix for 2.5 and later works when one disables "Activate mod_rewrite support?"
The issue seems to be as follows (or at least as best as I understand it):
in artikel.php
changes the "#AnchorName" to "index.php?action=artikel&lang=en&cat=NN&id=NN&artlang=LL#AnchorName"
and later
replaces the url to be SEO friendly. However, the parsing in Link.php breaks the url by the & and then into key / value pairs in the function getHttpGetParameters(). This results in the key artlang having the value LL#AnchorName which includes the in page anchor reference name. When it builds the url to be SEO friendly in the function toString the code
does not make use of artlang thus dropping the #AnchorName from the url.
Sorry I don't have a patch for you but I hope this helps.
Lidio.
I believe the above fix for 2.5 and later works when one disables "Activate mod_rewrite support?"
The issue seems to be as follows (or at least as best as I understand it):
in artikel.php
Code: Select all
$fixedContent = str_replace('href="#',
sprintf('href="index.php?action=artikel&lang=%s&cat=%d&id=%d&artlang=%s#',
$LANGCODE,
$currentCategory,
$faq->faqRecord['id'],
$LANGCODE),
$content);
and later
Code: Select all
$newFaqPath = $oLink->toString();
$fixedContent = str_replace($_url, $newFaqPath, $fixedContent);
replaces the url to be SEO friendly. However, the parsing in Link.php breaks the url by the & and then into key / value pairs in the function getHttpGetParameters(). This results in the key artlang having the value LL#AnchorName which includes the in page anchor reference name. When it builds the url to be SEO friendly in the function toString the code
Code: Select all
case PMF_LINK_GET_ACTION_ARTIKEL:
$url .= PMF_LINK_CONTENT.$getParams[PMF_LINK_GET_CATEGORY].PMF_LINK_HTML_SLASH.$getParams[PMF_LINK_GET_ID].PMF_LINK_HTML_SLASH.$getParams[PMF_LINK_GET_ARTLANG].PMF_LINK_SLASH.$this->getSEOItemTitle().PMF_LINK_HTML_EXTENSION;
if (isset($getParams[PMF_LINK_GET_HIGHLIGHT])) {
$url .= PMF_LINK_SEARCHPART_SEPARATOR.PMF_LINK_GET_HIGHLIGHT.'='.$getParams[PMF_LINK_GET_HIGHLIGHT];
}
break;
does not make use of artlang thus dropping the #AnchorName from the url.
Sorry I don't have a patch for you but I hope this helps.
Lidio.