Sometimes when you have a list of articles on one page, such as a category blog layout, you might like to create a link to that page that jumps straight to the start of a particular article. It is easy to create an anchor within an article with Joomla, but making the title an anchor is rather tricky. Here's how to do it.

Wait a minute. What's an anchor?

An anchor is a link within a page. Typically, you'll link to an external page with code like this:
{code}Google.com{/code}

 

But what if you wanted to link to a specific place on the same page? Well, first you'd have to create an anchor to act as your target. Here's what anchor code looks like – in this case, we've named the anchor "Jerry":
{code}Text{/code}

(Note: As with all tags, the text inside the tag can be whatever you want. In this case, I put "Text.")

You can now link directly to that point on the page from within that page with code like this:
{code}Go!{/code}

But anchors are even more useful. Let's say you're linking into this page from an external location, and you want to direct the web surfer down to that "Jerry" anchor. Easy. Just add this:
{code}#Jerry{/code}

... to the end of the URL. For example, if the page URL is http://www.joomlavideodemo.com/mypage.php and you want to link to an anchor on that page labeled "Jerry", the URL reference you would use is:
{code}Go!{/code}

Joomla makes anchors easy.

As you may have seen in our advanced Joomla tutorials, Joomla has an easy way to add anchors to the content of articles, but unfortunately, turning an article title into an anchor is a little more complicated. You'll need to be comfortable modifying template code in order to make this happen. So let's go!

Be kind, back up.

Before we move forward, be sure to back up your site files and database – just in case! At the very least, make a backup of your template file.

Here's how to do it.

Before we talk about the template file, let's talk about how we're going to provide Joomla with the name of the anchor to begin with. In this case, we're going to make use of an available field in Administrator. Open an article and look under the "Advanced Parameters" option and look for the "key reference" field. That's where you'll put the name of your anchor.

How to make Joomla article titles into anchors

For this exercise, let's simply put "anchor."

How to make Joomla article titles into anchors

Now for the code. There are various Joomla files where you can make this change, but in this example, we are going to just make the change to "category blog layout" pages. Connect to your site using FTP and look inside your active template folder. For example, if your template is named "mytemplate", look to see if you have this file:

/templates/mytemplate/html/com_content/category/blog_item.php

If you have this file, then that's the one you modify. But there is a good chance that you don't have this file in which case do the following. If necessary, create the above folder on your server i.e.

/templates/mytemplate/html/com_content/category/

Download this file to your computer:

/components/com_content/views/category/tmpl/blog_item.php

and upload this file to the folder you previously created:

/templates/mytemplate/html/com_content/category/

You can now modify this file without disturbing the rest of your Joomla site. Open this file on your local computer:

/templates/mytemplate/html/com_content/category/blog_item.php

and look for this code at around line15:
{jb_greenbox}<td class="contentheading<?php echo $this->escape($this->lparams->get('pageclass_sfx')); ?>" width="100%">{/jb_greenbox}

Above this line, add the following code:

{jb_greenbox}<?PHP if( strlen($this->item->params->get('keyref')) > 0 ) { echo '<a name="'.$this->item->params->get('keyref').'"></a>'; }  ?>{/jb_greenbox}

That's it! If you include a "key reference" in an article, you can now create an anchor link to this reference for category blog layout pages. You can modify other Joomla layout pages by using the same technique.

Credit: Joomla Forum