Drupal7: Adding a permalink to Node content Part 2 of 2

David G - DrupalIn part 1 of this blog post we discussed how to embed a canonical url and shortlink into the source code of an HTML web page. We also discussed how to avoid impacting SEO with multiple urls for identical content by using the Global Redirect module. In this blog post I’ll describe a way to insert the shortlink onto the web page in a simple and reusable format for most any Content Type in your Drupal website.

The Desired Output We Want to Achieve

In addition to embedding the shortlink and canonical urls within the source of the webpage. We would like to show the shortlink on the page as raw text (not a URL) so that the page can be cited in bibliographies and online citations. By default, Drupal will not do this for us. Our legacy website we’re importing into Drupal 7 as a project I’m working on has such an example:

On our legacy website all the primary document pages contain the raw url of the item from the legacy system.

On our legacy website all the primary document pages contain the raw url of the item from the legacy system.

So we want to mimic this using standard Drupal tools and conventions. Typical Drupal tools we might try to utilize are for example:

  • If possible can we make the shortlink text a drupal Field to place within content?
  • Do we have to write custom code to access the shortlink value, or perhaps is there a Token we can make use of?
  • Do we have to create custom template files to place this shortlink at the bottom of these template files? Or, is there a simpler means to control when/how this content is displayed?

The Recipe to Show ShortLink on Content Types

Lately, I’ve been making heavy use of the Display Suite module. I’ve covered DS in the past here at Arvixe and this is another case where it makes our life easier. In a nutshell, we can:

  • Create a pseudo field using Display Suite, which uses a Token to make the shortlink into a Drupal Field which is available to any Drupal content type (Node).

This is exactly what we want and it’s relatively simple to setup after you have installed Display Suite and the Token modules.

We want to create a DS "code field" called Citation which will contain code to show our shortlink.

We want to create a DS “code field” called Citation which will contain code to show our shortlink.

By creating a custom DS field, this field may be available to any Node (Content Type) we create in the system. So we can create this once and reference it whenever in the system — now with the existing Content Types. Or, 2 years from now when additional content types have been added into the system.

The configuration for our DS field is as follows. Note it is limited just to Nodes and it makes use of some tokens.

The actual configuration of our custom Display Suite field. Since the site builders are creating this field we have no problem using FULL_HTML input format.

The actual configuration of our custom Display Suite field. Since the site builders are creating this field we have no problem using FULL_HTML input format.

But, what tokens are we using here:

  •  [metatag:shortlink] is the short url link to our content in the format of /node/NID in this case for a Drupal website.
  • [node:title] is the title of the piece of content the visitor is viewing.

These pieces of information allow for a valid citation to be referenced by 3rd party researchers and the media when referencing our website.

Next, we simply assure that the view_mode of the content using Display Suite has embedded the Citation field into the page somewhere, ideally at the bottom of the page:

We change the view mode of our content type to include our custom shortlink field called "Citation" at the bottom of the page.

We change the view mode of our content type to include our custom shortlink field called “Citation” at the bottom of the page.

Note, that the label of the psuedo field becomes the Label of the field in Drupal … and that there’s no need to add colons at the end of our label by hand — Drupal takes care of that formatting for us.

If we visit the page now we will see the desired output:

Citation field embedded at the bottom of the page.

Citation field embedded at the bottom of the page.

Looking for quality web hosting? Look no further than Arvixe Web Hosting!

 

Tags: , , , , | Posted under Drupal | RSS 2.0

Author Spotlight

David Gurba

I am a web programmer currently employed at UCSB. I have been developing web applications professionally for 8+ years now. For the last 5 years I’ve been actively developing websites primarily in PHP using Drupal. I have experience using LAMP and developing data driven websites for clients in aviation, higher education and e-commerce. If you’d like to contact me I can be reached at david.gurba@arvixe.com

Leave a Reply

Your email address will not be published. Required fields are marked *