Best way to link articles in body text

lemmax - January 2, 2009 - 04:41

My site has been running for just a couple of days and I'm now adding content. I'm using some of the default content types (Page, Story, etc.) and have also defined some of my own custom types using the CCK. I've also installed and configured pathauto and everything seems to be working well.

Some of my content should cross-reference using hyperlinks and I'm wondering what's the best way to go about adding the links. For example, I might have a sentence that says "peanut butter makes you fat" and I want the word "butter" to link to another node. The simple way to do this would be to add a regular html link using the url alias (or node/.......) but what if that path gets changed at a later date? Presumably I'd have to go back and change all links to that new url. Is there some code or shortcut I can use to create more easily maintained links?

All suggestions appreciated. Thanks.

This might work.

vsr - January 2, 2009 - 05:48

Good, but not quite what I need

lemmax - January 2, 2009 - 06:49

Thanks for suggesting the alinks module. After following up your suggestion, I see that alinks can be used to generate internal links automatically. That's great and I may well use it but it's not quite what I am looking for at present. Let me see if I can explain my current requirement more clearly.

When coding ordinary html files we can link between pages using the "a" element and "href" attribute. As you know, href values can be absolute or relative. Absolute values are not portable (for example, if the base url changes) and relative values are more portable unless the relative path between the two pages change. When coding my page content using drupal, I must sometimes link between pages from the body text. I don't want to use absolute urls in case the base url changes, and I'm unsure if relative urls are a good idea as paths may change in the future (if for example I reconfigure pathauto settings). OK, I know you can use url rewriting and there's a module for this somewhere, but...

So, instead of writing an href such as "/node/100" what I'd like to write is href="[baseUrl]/node/100" and have drupal interpret that for me before rendering the page. ..........or............ is there some better solution that I'm missing? I'm sure many people must be using internal links in their body text and I'd like to know the best approach to take before I write too much content.

Thanks!

Decide what you want your critera to be portability or SEO

vsr - January 4, 2009 - 18:58

If you are using clear urls you can use the absolute url and people will remember it, good for repeat visit, also good if people download a page. Better for SEO if page name has keywords in name.

The relative urls will cause you headaches from remembering where a page is relative to the current page. If a base url is used in the document it will be easy to use. Just the path from the domain to the document. Does not work well if domain is not explicitly expressed. Relative urls are assumed to be relative to the current document nless a base url is supplied in the head section of the document. I do not think that a base url is added to the head section of a document, so you might have to modify your template to have a base url. Doing so might mess up other thing that are relative to drupal.

Using the /node/100 is great for portability from one site to another. Paths can change and the node number will always be the same. Not good for SEO. Better to have keyword rich page names. If using the path module you can have /node/100 redirected to a keyword rich name. The problem is that you have to know what /node/100 is and what the node number is for the document you want to link to is. If you do several sites this way, you will need to keep indexes of the nodes so that you know what node/100 is at each site. This breaks if somebody downloads the page and there is no base url in the head section.. Where is /node/100. What happens when you have 1000 nodes or 10,000 nodes. One mistake in the number can cause you to end up on the wrong page.

Using "[baseUrl]" like in the templates is for things relative to the drupal install. That varible is setup in the admin section. Used for finding templates, images for templates, modules; all that are under drupal. Usually documents are relative to the domain that they are part of.HTML comes with a base url tag and it goes in the head section of a document before any references to files.

Probably the best thing is to use the absolute URL. How often does a site change domains? People will remember it easier, Which wold you remember better, wonkachocolates.com/tripplechocolate.html or wonkachocolates.com/node/1072157? A keyword name makes it easier for tell other people. If the inside paths change, you will have the same problem with relative urls. How often do you reorganize the site structure? Having the keywords in the anchor text and the page name is good for SEO.

There is a module called pathlogic I think that is suppose to address the problem of paths changing..

You might want to look into the title module. Good for SEO.

 
 

Drupal is a registered trademark of Dries Buytaert.