The Joomla! Forum ™





Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 27 posts ] 
Author Message
PostPosted: Thu Sep 24, 2009 8:22 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Fri Sep 18, 2009 2:35 pm
Posts: 2
Inside the components\com_content\views\article\tmpl\default.xml, I added
Code:
            <param name="anchor" type="text" default="" label="Type Anchor Name (optional)" description="A named anchor in the article(optional)" />


That causes a textbox to show where you can enter the named anchor you want to link to when creating the menu item.

Inside modules\mod_mainmenu\helper.php, I changed
Code:
      default :
                              $router = JSite::getRouter();
          $tmp->url = $router->getMode() == JROUTER_MODE_SEF ? 'index.php?Itemid='.$tmp->id : $tmp->link.'&Itemid='.$tmp->id;
      break;
to
Code:
         default :
            $router = JSite::getRouter();
            //$tmp->url = $router->getMode() == JROUTER_MODE_SEF ? 'index.php?Itemid='.$tmp->id : $tmp->link.'&Itemid='.$tmp->id;
            if($iParams->get('anchor') != ''){
                $tmp->url = $router->getMode() == JROUTER_MODE_SEF ? 'index.php?Itemid='.$tmp->id : $tmp->link.'&Itemid='.$tmp->id.'#'.$iParams->get('anchor');
            }else{
                $tmp->url = $router->getMode() == JROUTER_MODE_SEF ? 'index.php?Itemid='.$tmp->id : $tmp->link.'&Itemid='.$tmp->id;            
            }
            
      break;




I've also attached the files.


You do not have the required permissions to view the files attached to this post.


Top
 Profile  
 
PostPosted: Fri Nov 06, 2009 5:56 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Nov 06, 2009 3:54 pm
Posts: 8
djb_excal wrote:
Inside the components\com_content\views\article\tmpl\default.xml, I added
Code:
            <param name="anchor" type="text" default="" label="Type Anchor Name (optional)" description="A named anchor in the article(optional)" />


That causes a textbox to show where you can enter the named anchor you want to link to when creating the menu item.

Inside modules\mod_mainmenu\helper.php, I changed
Code:
      default :
                              $router = JSite::getRouter();
          $tmp->url = $router->getMode() == JROUTER_MODE_SEF ? 'index.php?Itemid='.$tmp->id : $tmp->link.'&Itemid='.$tmp->id;
      break;
to
Code:
         default :
            $router = JSite::getRouter();
            //$tmp->url = $router->getMode() == JROUTER_MODE_SEF ? 'index.php?Itemid='.$tmp->id : $tmp->link.'&Itemid='.$tmp->id;
            if($iParams->get('anchor') != ''){
                $tmp->url = $router->getMode() == JROUTER_MODE_SEF ? 'index.php?Itemid='.$tmp->id : $tmp->link.'&Itemid='.$tmp->id.'#'.$iParams->get('anchor');
            }else{
                $tmp->url = $router->getMode() == JROUTER_MODE_SEF ? 'index.php?Itemid='.$tmp->id : $tmp->link.'&Itemid='.$tmp->id;            
            }
            
      break;




I've also attached the files.

Thanks alot for sharing!
But when I upload two files that I didn't see changing, I've insert the anchor in article. I am using Joomla 1.5.3. Do u show me how do you do? Step by step? Thanks!


Top
 Profile  
 
PostPosted: Sat Nov 07, 2009 4:57 pm 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Mon Aug 22, 2005 6:41 pm
Posts: 93
Location: Dallas, Georgia U.S.
Hi-
I've also tried your two files and I don't see the text box for adding the anchor. Could there be something causing the issue such as a 3rd party template or extension?

I was however able to make the anchors work by creating a menu link that also included the Itemid with the anchor tag after it:
Code:
index.php?option=com_content&view=article&id=31;Itemid=556;#p233

Works like a charm.

_________________
RJ
Atlanta, Georgia, US


Top
 Profile  
 
PostPosted: Sun Nov 08, 2009 3:13 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Nov 06, 2009 3:54 pm
Posts: 8
rjscott2005 wrote:
Hi-
I've also tried your two files and I don't see the text box for adding the anchor. Could there be something causing the issue such as a 3rd party template or extension?

I was however able to make the anchors work by creating a menu link that also included the Itemid with the anchor tag after it:
Code:
index.php?option=com_content&view=article&id=31;Itemid=556;#p233

Works like a charm.

You can login into Administrator/Menu and choose the menu which you can use. In the right you can see that box.


Top
 Profile  
 
PostPosted: Sun Nov 08, 2009 3:30 pm 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Mon Aug 22, 2005 6:41 pm
Posts: 93
Location: Dallas, Georgia U.S.
dhjoomla wrote:
rjscott2005 wrote:
Hi-
I've also tried your two files and I don't see the text box for adding the anchor. Could there be something causing the issue such as a 3rd party template or extension?

I was however able to make the anchors work by creating a menu link that also included the Itemid with the anchor tag after it:
Code:
index.php?option=com_content&view=article&id=31;Itemid=556;#p233

Works like a charm.

You can login into Administrator/Menu and choose the menu which you can use. In the right you can see that box.

I am not using the default admin template. Maybe that is why it isn't visible.

_________________
RJ
Atlanta, Georgia, US


Top
 Profile  
 
PostPosted: Sun Nov 08, 2009 3:58 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Nov 06, 2009 3:54 pm
Posts: 8
Could you choose again default template then try again. I don't think that is cause.


Top
 Profile  
 
PostPosted: Sun Nov 08, 2009 4:12 pm 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Mon Aug 22, 2005 6:41 pm
Posts: 93
Location: Dallas, Georgia U.S.
dhjoomla wrote:
Could you choose again default template then try again. I don't think that is cause.

I will try that and post the results. It may be a while though because my little son is in need of my undivided attention at the moment. :eek:

_________________
RJ
Atlanta, Georgia, US


Top
 Profile  
 
PostPosted: Mon Nov 09, 2009 6:33 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Nov 06, 2009 3:54 pm
Posts: 8
Ok! You are good father and happiness! I will try yourself and post again.


Top
 Profile  
 
PostPosted: Mon Nov 09, 2009 12:26 pm 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Mon Aug 22, 2005 6:41 pm
Posts: 93
Location: Dallas, Georgia U.S.
dhjoomla wrote:
Ok! You are good father and happiness! I will try yourself and post again.

Thanks :laugh:
I've attached screen grabs of each template while using the modified default.xml and helper.php files.
Attachment:
menu_item_default_template.jpg
Attachment:
menu_item_APLite_template.jpg

Parameters Advanced for both templates states: There are no Parameters for this Menu Item


You do not have the required permissions to view the files attached to this post.

_________________
RJ
Atlanta, Georgia, US


Top
 Profile  
 
PostPosted: Tue Nov 10, 2009 8:09 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Nov 06, 2009 3:54 pm
Posts: 8
rjscott2005 wrote:
dhjoomla wrote:
Ok! You are good father and happiness! I will try yourself and post again.

Thanks :laugh:
I've attached screen grabs of each template while using the modified default.xml and helper.php files.
Attachment:
menu_item_default_template.jpg
Attachment:
menu_item_APLite_template.jpg

Parameters Advanced for both templates states: There are no Parameters for this Menu Item

Oh, you only see if you choose type Internal link -> Article->Article Layout. I attached this my menu item. You can see it


You do not have the required permissions to view the files attached to this post.


Top
 Profile  
 
PostPosted: Tue Nov 10, 2009 10:49 am 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Mon Aug 22, 2005 6:41 pm
Posts: 93
Location: Dallas, Georgia U.S.
dhjoomla wrote:
rjscott2005 wrote:
dhjoomla wrote:
Ok! You are good father and happiness! I will try yourself and post again.

Thanks :laugh:
I've attached screen grabs of each template while using the modified default.xml and helper.php files.
Attachment:
menu_item_default_template.jpg
Attachment:
menu_item_APLite_template.jpg

Parameters Advanced for both templates states: There are no Parameters for this Menu Item

Oh, you only see if you choose type Internal link -> Article->Article Layout. I attached this my menu item. You can see it

Ah! I see it when I choose Internal Article. However after I enter the anchor, it still doesn't work. I've attached two screen grabs showing the anchor like
Code:
#anchor
and like
Code:
anchor
.
The outputted result is the same:
Code:
http://www.corpsvets.org/index.php?option=com_content&view=article&id=31&Itemid=200129
Attachment:
Menu Item_ [Edit]_1257849541230.png
Attachment:
Menu Item_ [Edit]_1257849520808.png


You do not have the required permissions to view the files attached to this post.

_________________
RJ
Atlanta, Georgia, US


Top
 Profile  
 
PostPosted: Thu Jan 14, 2010 1:17 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Thu Jan 14, 2010 12:18 pm
Posts: 2
Hi,

Has anyone managed to get this hack working properly yet?

I also downloaded the above PHP files and have got the 'anchor' field to appear when creating a menu, I then enter the anchor ID in the newly created menu article link box, but it makes no difference?

Anyone have any ideas if it is ONLY possible to add anchor links in by changing the menu links to URL's instead of internal Article Links?

I have over 600 pages of Internal Article links that I want to add a simple ' #contenttop ' suffix too, but I don't want to change 600 Article Links to URLS!?

Anyone have any thoughts?

Thanks in advance.

D.


Top
 Profile  
 
PostPosted: Fri Jan 29, 2010 10:24 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sun Mar 09, 2008 7:19 am
Posts: 11
I have managed to hack it successfully -

You need to edit 3 files ( two if you wish to put the anchor in each article )

1 -> administrator/components/com_menus/models/metadata/components.xml

After

<param name="menu_image" type="imagelist" directory="/images/stories" hide_default="1" default="" label="Menu Image" description="PARAMMENUIMAGE" />

add this line
Code:
<param name ="anchor" type ="text" size="20" label="Named Anchor" description="named anchor , must include #"  default="#content"/>



2-> in modules/mod_mainmenu/helper.php , change

This

Code:
    default :
                              $router = JSite::getRouter();
          $tmp->url = $router->getMode() == JROUTER_MODE_SEF ? 'index.php?Itemid='.$tmp->id : $tmp->link.'&Itemid='.$tmp->id;
      break;


to

This
Code:
 default :
            $router = JSite::getRouter();
            if($iParams->get('anchor') != ''){
                $tmp->url = $router->getMode() == JROUTER_MODE_SEF ? 'index.php?Itemid='.$tmp->id : $tmp->link.'&Itemid='.$tmp->id.'#'.$iParams->get('anchor');
            }else{
                $tmp->url = $router->getMode() == JROUTER_MODE_SEF ? 'index.php?Itemid='.$tmp->id : $tmp->link.'&Itemid='.$tmp->id;           
            }
           
      break;





3->

In your active template , just before the
Code:
 <jdoc:include type="component" />


place

Code:
<a name ="content" />


and you are all done :)

PS : You can skip the last step if you wish to put the anchor in the article , or somewhere else in the template , just remember to change it from menu manager -> your menu -> parameters ->system

Shoot me a mail on info@joompros.com if you have any doubts.

_________________
Offering professional PSd to Joomla Template Conversion services , Custom Joomla Templates , Joomla trobuleshooting , html to joomla ,Custom components- I love joomla !!!
http://www.joompros.com


Top
 Profile  
 
PostPosted: Mon Feb 01, 2010 11:41 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Thu Jan 14, 2010 12:18 pm
Posts: 2
Thanks for the clear explanation...i'll give it a try.

Dave.


Top
 Profile  
 
PostPosted: Mon Feb 01, 2010 11:34 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Jun 09, 2007 11:01 pm
Posts: 23
Location: St. Louis, MO - USA
@h40534 - Your solution works, except there's no need to add the '#' - for whatever reason. When reviewing the generated URL, it's already added. If you do add it, it doubles up. Thanks for the solution though - it works great.

For those wondering why do it this way rather than simply using 'External Link' and adding the Alias there - is because you don't have the ability to publish Modules to the menu item if it's an External Link.

This solution preserves the 'Article' format (and the ability to publish specific modules to that page) while still providing a way to target specific content within that Article.

Thanks again!

_________________
http://www.dijitalmedia.com/e-marketing.html
http://www.dijitalmedia.com/it-services.html


Top
 Profile  
 
PostPosted: Tue Feb 02, 2010 8:38 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sun Mar 09, 2008 7:19 am
Posts: 11
@jgohil - Thanks for mentioning that , i forgot to add it in the description :)

_________________
Offering professional PSd to Joomla Template Conversion services , Custom Joomla Templates , Joomla trobuleshooting , html to joomla ,Custom components- I love joomla !!!
http://www.joompros.com


Top
 Profile  
 
PostPosted: Fri Feb 19, 2010 10:46 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Feb 19, 2010 6:20 pm
Posts: 5
Thanks guys, any suggestions for making it work with the default Joomla! SEF Urls?


Top
 Profile  
 
PostPosted: Sat Feb 20, 2010 12:38 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Feb 19, 2010 6:20 pm
Posts: 5
decay1969 wrote:
Hi,

Has anyone managed to get this hack working properly yet?

I also downloaded the above PHP files and have got the 'anchor' field to appear when creating a menu, I then enter the anchor ID in the newly created menu article link box, but it makes no difference?

Anyone have any ideas if it is ONLY possible to add anchor links in by changing the menu links to URL's instead of internal Article Links?

I have over 600 pages of Internal Article links that I want to add a simple ' #contenttop ' suffix too, but I don't want to change 600 Article Links to URLS!?

Anyone have any thoughts?

Thanks in advance.

D.


'h4053' code worked best for me. Be sure to make your menu links article/blog layout (not direct article). This works perfectly for non SEF urls as they #named-anchor is appended successfully to the url - However with SEF Urls enabled in the global configuration Joomla treats the new menu item alias as a sub section of the root page (basically it puts a '/' instead of a '#').

since special characters can't be used for unique aliases, simply adding the # to that won't work either. Since SEF URLs are more important I'm having to look for an alternate way to push directly to named anchors from menu items


Top
 Profile  
 
PostPosted: Thu Jul 15, 2010 12:43 am 
User avatar
Joomla! Hero
Joomla! Hero

Joined: Fri Jan 20, 2006 11:37 am
Posts: 2610
Location: Forrest Australia
Just found this topic, and thought I would share how I just solved this problem.

The issue was that my client wanted to be able to have me fire off external links that landed on the blog layout page, but jumped down to the specific blog item (hence an anchor link). Trouble is that Joomla doesn't by default offer an "Anchor" tag option.

So, by using Template Overrides, I added the follow line to the blog_item.php file right below the area that produces the article title.
Code:
<a name="<?php echo $this->escape($this->item->alias); ?>" id="<?php echo $this->escape($this->item->alias); ?>"></a>


Here is an example of this working.
http://www.villawoodproperties.com.au/v ... tlandsales
Which is an anchor link to a specific article contained within a category blog layout.

This shows yet again the power of template overrides, as this now puts an anchor link named the same as the article alias right below every article title across all blogs on your site.

You will need to learn more about Template overrides before implementing this technique.

Good luck

_________________
Step1. Read the instructions. Step2. Refer to step 1. Step 3. Backup
Can't find the answers you need?
Joomla Video Tutorials ~>
http://www.teachingjoomla.com


Top
 Profile  
 
PostPosted: Fri Sep 24, 2010 12:32 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Fri Sep 24, 2010 12:24 am
Posts: 2
Norm, could you be more specific (just pretend im a noob.. ;) )about where to paste that code pls?

thnx, youre a great help!



Sid


Top
 Profile  
 
PostPosted: Fri Sep 24, 2010 9:53 am 
User avatar
Joomla! Master
Joomla! Master

Joined: Thu Jul 17, 2008 3:10 pm
Posts: 10948
Location: Ireland
  1. create a folder in your template folder called "html" (if it doesn't exists)
  2. create a folder in that html folder called "com_content" (if it doesn't exists)
  3. create a folder in that com_content folder called "category" (if it doesn't exists)
  4. copy the file .../components/com_content/views/category/tmpl/blog_item.php in this .../templates/[your-template]/html/com_content/category/ folder
  5. open that file
  6. find the following lines:
    Code:
    <a href="<?php echo $this->item->readmore_link; ?>" class="contentpagetitle<?php echo $this->escape($this->item->params->get( 'pageclass_sfx' )); ?>">

  7. and replace it with the following:
    Code:
    <a name="<?php echo $this->escape($this->item->alias); ?>" id="<?php echo $this->escape($this->item->alias); ?>"></a>
    <a href="<?php echo $this->item->readmore_link; ?>" class="contentpagetitle<?php echo $this->escape($this->item->params->get( 'pageclass_sfx' )); ?>">
  8. save the file

You might need to use a different view, e.g. the section view, or the frontpage view.

Olaf

_________________
Olaf Offick - Global Moderator
http://learnskills.org


Top
 Profile  
 
PostPosted: Sun Sep 26, 2010 7:56 am 
User avatar
Joomla! Ace
Joomla! Ace

Joined: Fri Oct 19, 2007 10:34 pm
Posts: 1041
Location: Australia
If all you need is a mune item pointing to an anchor within an article, then rjscott2005's simple way works just fine.

Note you must chose External Link as the menu type.

You can see this in his attached screenshots.

Answered my question straight up! Thanks rjscott2005 (your little son will be 5 years older as I read this!)

J

_________________
"Things not being necessary is what makes life interesting" -- Stephen Fry
This is necessary - http://docs.joomla.org/


Top
 Profile  
 
PostPosted: Sun Sep 26, 2010 2:53 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Fri Sep 24, 2010 12:24 am
Posts: 2
ooffick wrote:
  1. create a folder in your template folder called "html" (if it doesn't exists)
  2. create a folder in that html folder called "com_content" (if it doesn't exists)
  3. create a folder in that com_content folder called "category" (if it doesn't exists)
  4. copy the file .../components/com_content/views/category/tmpl/blog_item.php in this .../templates/[your-template]/html/com_content/category/ folder
  5. open that file
  6. find the following lines:
    Code:
    <a href="<?php echo $this->item->readmore_link; ?>" class="contentpagetitle<?php echo $this->escape($this->item->params->get( 'pageclass_sfx' )); ?>">

  7. and replace it with the following:
    Code:
    <a name="<?php echo $this->escape($this->item->alias); ?>" id="<?php echo $this->escape($this->item->alias); ?>"></a>
    <a href="<?php echo $this->item->readmore_link; ?>" class="contentpagetitle<?php echo $this->escape($this->item->params->get( 'pageclass_sfx' )); ?>">
  8. save the file

You might need to use a different view, e.g. the section view, or the frontpage view.

Olaf




Fantastic! thanks! :)


Top
 Profile  
 
PostPosted: Tue Oct 19, 2010 12:14 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Tue Oct 19, 2010 12:08 am
Posts: 3
Thank you for this post, it worked great for me.

I wonder if it is possible to add this anchor functionality for the contact component? I am fairly new to this so any help would be appreciated on how and where to add code to allow linking to an anchor (e.g. top of article) on a contact page. I mean, where to add the actual anchor code as you can't edit HTML like in a normal article.

Thank you!


Top
 Profile  
 
PostPosted: Tue Dec 14, 2010 12:34 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Sep 19, 2008 4:16 pm
Posts: 29
ok, so this is going to kill you guys.....this is only for someone that wants a quick Menu Item External link to an anchor in an article and is using Joomla SEF settings.

Step 1: Create an html file and name it whatever you'd like
- ex: http://yoursite.com/anchor.html
- add the following to the html file:

<html>
<head>
<title>History of On-Cor</title>


<meta http-equiv="refresh" content="0;url=http://www.yoursite.com/about.html#anchor">
</head>
<body>
</body>
</html>

Step 2:
Create an external link to an article:
ex: http://yoursite.com/anchor.html

Step 3: publish new menu item!


Top
 Profile  
 
PostPosted: Tue Dec 14, 2010 7:17 am 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Thu Sep 09, 2010 6:20 pm
Posts: 52
Location: LOS ANGELES, CA 90015 UNITED STATES
Although I took me some time to understand what you all are trying to achieve here, but @ooffick and "template overriding" made the picture crystal clear.

Instead of hacking any files, template overriding is always better option. Never never try to hack any joomla files unless its absolutely necessary.

This way your core joomla files are intact and you can upgrade to latest version of joomla without worrying about your changes getting over written.

_________________
Joomla Rocks :)
Thanks and Regards, Richard Philips
http://www.htmltojoomla.com
HTML to Joomla Conversion | Convert Static HTML website to Joomla Website


Top
 Profile  
 
PostPosted: Sat Jan 22, 2011 4:43 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Sat Jan 22, 2011 4:26 am
Posts: 2
All these solutions seem quite complex.
Why not simply add &#anchor at the end of the URL?

Example:
Code:
index.php?option=com_content&view=article&id=47&Itemid=57&#anchor

where
  • index.php is the Home URL for Joomla
  • option=com_content&view=article&id=47 is the place you are going to
  • Itemid=57 is the place you are coming from
  • #anchor is the name of your anchor

This approach will preserve breadcrumbs and rewritten localized URLs, whereas using an external link would not.
Tested this in Joomla 1.5.22

X


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 27 posts ] 



Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group