Hide "Home" link on navigation when user is on the home page

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
joecannes
Forum Members
Forum Members
Posts: 93
Joined: Mon Nov 26, 2007 5:00 pm
Location: Montreal, Quebec

Hide "Home" link on navigation when user is on the home page

Post by joecannes »

This may be a simple answer, but I cant find it and I am a newbie!

How do I not show the "Home" link in the navigation on the home page, but it appears when I am navigating other pages?


JC
belgirl
Forum Members
Forum Members
Posts: 61
Joined: Thu Jan 17, 2008 7:45 pm

Re: Hide "Home" link on navigation when user is on the home page

Post by belgirl »

I would like to do the same thing, please! 
RonnyK
Support Guru
Support Guru
Posts: 4963
Joined: Wed Oct 25, 2006 8:29 pm
Location: Raalte, the Netherlands

Re: Hide "Home" link on navigation when user is on the home page

Post by RonnyK »

Do you mean in the regular menu, or in a link?

SHould other pages that are being shown at the time, not be shown in the menu while showing?

Ronny
NaN

Re: Hide "Home" link on navigation when user is on the home page

Post by NaN »

You could modify your menu template.
You just need to check for the contents alias or the contents id.

In the backend in "Layout->MenuManager" select the template you use for your page.
(If it is not imported to the database do so and modify your template by using this template instead. Or just browse with an FTP programm to the folder modules/MenuManager/templates and modify the file directly.)

Within your template should be something like this (in this case the example code is taken from the original simple_navigation.tpl):

Code: Select all


{if $node->current == true}
<li class="currentpage"><h3><dfn>Current page is {$node->hierarchy}: </dfn>{$node->menutext}</h3>

This is where the template styles the current pages link. (in this case it is a headline ...)
There you just need to insert below the {if $node->current == true} an additional if-loop to check the contents alias (or the contents id - whatever makes you happy):

{if $node->current == true}
{if ($node->alias=='home'}
{if $node->current == true}
Current page is {$node->hierarchy}: {$node->menutext}
{/if}
So whenever the current content is "home" it wont be displayed in the menu.
You also could give the an id with the pages alias and hide the menu link via stylesheets:

{if $node->current == true}
alias" [/b]>Current page is {$node->hierarchy}: {$node->menutext}
Now you just need to add to your stylesheets:

Code: Select all


ul li#home {
   display:none;
   margin: 0;
   padding: 0;
   border: none;
}

belgirl
Forum Members
Forum Members
Posts: 61
Joined: Thu Jan 17, 2008 7:45 pm

Re: Hide "Home" link on navigation when user is on the home page

Post by belgirl »

Thanks--for me, it would be hiding a home link--not in the menu. (like a "back" button) Is this possible?
RonnyK
Support Guru
Support Guru
Posts: 4963
Joined: Wed Oct 25, 2006 8:29 pm
Location: Raalte, the Netherlands

Re: Hide "Home" link on navigation when user is on the home page

Post by RonnyK »

If you only want a specific link want to be shown on all pages but the HOME-page, you could insert something like the {cms_selflink} to the homepage, wrapped inside an if statement.

So with the cms_selflilnk:
{if $pagealias neq 'home'}
{cms_selflink page="home" text="Home"}
{/if}
or with a a-href:
{if $pagealias neq 'home'}
Home
{/if}
Ronny
belgirl
Forum Members
Forum Members
Posts: 61
Joined: Thu Jan 17, 2008 7:45 pm

Re: Hide "Home" link on navigation when user is on the home page

Post by belgirl »

The home link I have is currently in the template.  Can that cms_selflink be used in template or does it have to actually be used in the home page only?

Thanks!
NaN

Re: Hide "Home" link on navigation when user is on the home page

Post by NaN »

It can be placed anywhere you want it to.
Because the link is only shown if you are notat a specific page.
In this case the link is only shown if the page alias (wich you can set at the options tab when editing a page; by default it will be filled automatically by a "websafe" version of the menu text) is not "home".
I would prefere to place it in the Template. (Since it is seen at every page except the page you specified.)
In order to get always the right link to that page i would use the first version of Ronnys examples.
belgirl
Forum Members
Forum Members
Posts: 61
Joined: Thu Jan 17, 2008 7:45 pm

Re: Hide "Home" link on navigation when user is on the home page

Post by belgirl »

Hmmm..neither of these examples are working for me.  This is what I have in the template:

{if $pagealias neq 'micro-auto-paint'}
{cms_selflink page="micro-auto-paint" text="Return to Micro Auto Paint"}
{/if}

I do have friendly urls although I don't know if that would make a difference.  The link is still showing up on the "micro-auto-paint" page.  I have doubled checked the page name, and it is correct.  What am I doing wrong?  :(
NaN

Re: Hide "Home" link on navigation when user is on the home page

Post by NaN »

Maybe the variable $pagealias is wrong.
Try $page_alias, $content_alias, $content_name or $page_name... just type {get_template_vars} in your template to see what variables contains what values.

Or the alias of the page is not "micro-auto-paint"? Take a look into the options tab again when editing that page to get the right alias.

I'm not sure but since you are using "-" within your alias it could be that you need to use the double quotes (") instead of single qoutes (').
belgirl
Forum Members
Forum Members
Posts: 61
Joined: Thu Jan 17, 2008 7:45 pm

Re: Hide "Home" link on navigation when user is on the home page

Post by belgirl »

Hi-- my page alias is correct--double quotes didn't work.  :(  Any other ideas?
viebig

Re: Hide "Home" link on navigation when user is on the home page

Post by viebig »

on your template

Code: Select all

{if $page_alias == 'home'}
{menu excludeprefix='home'}
{else}
{menu}
{/if}
viebig

Re: Hide "Home" link on navigation when user is on the home page

Post by viebig »

belgirl wrote: Hi-- my page alias is correct--double quotes didn't work.   :(  Any other ideas?
use $page_alias with the underline
belgirl
Forum Members
Forum Members
Posts: 61
Joined: Thu Jan 17, 2008 7:45 pm

Re: Hide "Home" link on navigation when user is on the home page

Post by belgirl »

viebig wrote:
belgirl wrote: Hi-- my page alias is correct--double quotes didn't work.   :(  Any other ideas?
use $page_alias with the underline
THAT WAS IT!!  I was simply missing the underscore..Ah...brilliant!  Thanks everyone.  Working great!
Post Reply

Return to “Developers Discussion”