Anchor to title of article

General questions relating to Joomla! 1.5 There are other boards for more specific help on Joomla! features and extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Locked
potski205
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Tue Oct 19, 2010 12:08 am

Anchor to title of article

Post by potski205 » Tue Oct 26, 2010 2:53 pm

Hi,

I wonder if anyone can help. I would like to add an anchor to an article title (or just above) so links from the menu navigates down but still shows the title.

I already added code from another post:
http://forum.joomla.org/viewtopic.php?f=178&t=444075

to add anchor text to an article but the title is cut off as it only links to the main article body and so makes navigation a little confusing.

Here is an example:
http://www.cloudcreative.co.uk (links from top menu)

Also, this does not work for the contact article as you cannot edit the HTML. Or the default home link as if you select it as default, #mainbody anchor is not added.

Is there a solution for these issues?

Many thanks in advance for the help.

User avatar
factor41
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Tue Jun 30, 2009 1:52 pm

Re: Anchor to title of article

Post by factor41 » Tue Nov 09, 2010 5:37 pm

Bump!

I'm after something very similar. I'm linking from side menus to simple #anchors as an external URL menu type to a point within a Category Blog layout. I can link to anchors within the individual articles without a problem, but would like to get the anchor in or just above the article title.

I imagine it would be fairly simple to use a field such as the keyReference field and put an anchor name into there, then when the page is assembled, simply check for it like

Code: Select all

if ($params->get('keyref')) { ...
And if it exists for that article, drop in the anchor with that name in just before the title. Unfortunately, I can't make head nor tail of the PHP files where Joomla is actually assembling the file so can't figure out where or how to implement this.

If anyone could shed any light, I'd be very grateful!

Thanks

User avatar
factor41
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Tue Jun 30, 2009 1:52 pm

Re: Anchor to title of article

Post by factor41 » Wed Nov 10, 2010 12:37 pm

Ok, been doing some digging and I've found that the file within my template>html>com_content_category>blog_item is the bit that I can add in so I get an anchor above each title. Can anyone tell me what I would need to add as the name part in order to get the key reference to be used as the anchor name. Something like...

Code: Select all

<?php if ($this->item->params->get('show_title')) : ?>
<a name="<?php $this->item->params->get('keyref') ?>"></a>
<h2 class=...
(I'm guessing it's not as simple as that, because this doesn't work!)

Thanks

User avatar
factor41
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Tue Jun 30, 2009 1:52 pm

SOLVED!

Post by factor41 » Wed Nov 10, 2010 1:06 pm

SORTED IT! - silly me, forgot to actually echo the variable. Potski205 - this looks like it solves your problem as it has mine.

For creating anchors for each article in a category blog, simply go to the file yourTemplate>html>com_content>category>blog_item and just before the <h2> which creates the item header, insert the line...

Code: Select all

<?PHP if( strlen($this->item->params->get('keyref')) > 0 ) { echo '<a name="'.$this->item->params->get('keyref').'"></a>'; }  ?>
With this in place, if you put in a value in the Key Reference box on your article, it will create an anchor with that name, just above your article header.

If you want something similar on a section blog, frontpage or individual article layout, there are similar files within that template folder.

:D

jayflux
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 110
Joined: Sun Jul 25, 2010 3:02 pm

Re: Anchor to title of article

Post by jayflux » Mon Dec 20, 2010 12:18 pm

Not working for me, its not picking up keyref, when i remove the if statement it shows the <a name.....
but it has nothing in it.

Is 'keyref' the correct parameter?

Millernasha
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Mon Dec 20, 2010 12:30 pm

Re: Anchor to title of article

Post by Millernasha » Mon Dec 20, 2010 12:49 pm

What exactly can you do with an anchor text? Does it help spreading the side and getting more readers? How do you prove that the anchor text really is working and actually helping out your page?

What is the actual myth about having an anchor text - is it really necessary?

jayflux
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 110
Joined: Sun Jul 25, 2010 3:02 pm

Re: Anchor to title of article

Post by jayflux » Mon Dec 20, 2010 10:19 pm

@miller

you seem to have anchor text confused with something else SEO.

Anchor text means you can navigate to a certain part of your page.
So if i wanted to link someone to a paragraph half way down a page I could do it with an anchor text.

http://en.wikipedia.org/wiki/Anchor_text

User avatar
factor41
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Tue Jun 30, 2009 1:52 pm

Re: Anchor to title of article

Post by factor41 » Thu Dec 23, 2010 5:59 pm

jayflux wrote:Not working for me, its not picking up keyref, when i remove the if statement it shows the <a name.....
but it has nothing in it.

Is 'keyref' the correct parameter?
Yes, keyref seems to work fine for me - just put the text in the keyref box on the article and it appears in the code. Don't include the '#' in the name.

Are you sure you copied the code exactly?

merlin_runner
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Sun Dec 18, 2011 12:48 pm

Re: Anchor to title of article

Post by merlin_runner » Sat Jan 14, 2012 12:11 pm

Hi, I have come across this problem and want to link to an article title rather than a category blog. Being a newbie a bit unsure which file I need to alter and which part of it. Any help would be much appreciated.

User avatar
offhegoes
Joomla! Apprentice
Joomla! Apprentice
Posts: 31
Joined: Fri Aug 15, 2008 5:27 pm
Location: Bandar Baru Bangi, Selangor, Malaysia
Contact:

Re: Anchor to title of article

Post by offhegoes » Thu Jun 20, 2013 7:29 am

Hi, I solved this issue & I am running on Joomla! 2.5

Solutions: Every article will have an anchor named #titlearticle or whatever name you would like to have, it will be use by the menu to call later.

How:
1. Open file at the location /templates/<template_name>/html/joomla/2.5/com_content/article/default.php

Example: /templates/rt_chapelco/html/joomla/2.5/com_content/article/default.php

2. Look for this code

Code: Select all

<div class="rt-article-title">
at line 36. Before that line, add one new line of code

Code: Select all

<a name="titlearticle"></a>
3. Then, you can add a menu with that anchor.

Example: http://www.huemedia.com.my/index.php/co ... tlearticle

Hope this will help everyone who would like to have this solution.

Thanks ;)


Locked

Return to “General Questions/New to Joomla! 1.5”