Post by itrends » Tue Jul 21, 2009 4:34 pm

Anyone able to help? :)

How to hide the breadcrumb trail if on the homepage?

Thanks!

Active Member

Posts

Joined
Tue Jul 14, 2009 7:54 pm

Post by richard » Wed Jul 22, 2009 5:08 am

Hello..

This works for me:
1. open the 'layout.php' file in '\catalog\controller\common' (back it up first to be sure)
2. look for this piece of code: (line #19 ??)

Code: Select all

$this->data['breadcrumbs'] = $this->document->breadcrumbs;
3. replace it with this code:

Code: Select all

$request = new Request();
if($request->get['route']=='common/home'){
	$this->data['breadcrumbs'] = array();
}else{
	$this->data['breadcrumbs'] = $this->document->breadcrumbs;	
}
       
Basically your testing if you are on the 'Home' page, if yes, clear the 'breadcrumbs' array, if no,
display it normally.

Hope that helps.
:)

Image a point in time
http://richarrdg.tumblr.com/


New member

Posts

Joined
Wed Jul 08, 2009 2:09 pm

Post by itrends » Wed Jul 22, 2009 5:33 am

Yup that conditional is what I was looking for as I want to use it elsewhere :)

Thanks!

Active Member

Posts

Joined
Tue Jul 14, 2009 7:54 pm

Post by Leon » Wed Jul 22, 2009 7:42 am

This creates a bug for me if you just visit the site without index.php?route=common/home in the domain; you get a warning error at the top of the screen, and the breadcrumb still exists.

Active Member

Posts

Joined
Tue Apr 07, 2009 1:20 am

Post by richard » Wed Jul 22, 2009 3:09 pm

Hi.

Yes, you will have an error since the 'route' key is not set.
In this case,you can use isset() or maybe empty() as a test, then use the code above.

Hope that helps!
:)

Image a point in time
http://richarrdg.tumblr.com/


New member

Posts

Joined
Wed Jul 08, 2009 2:09 pm

Post by Leon » Wed Jul 22, 2009 5:41 pm

I don't have much knowledge in php, but i just researched isset and empty, and have come up with what i think you mean.

Find

Code: Select all

$this->data['breadcrumbs'] = $this->document->breadcrumbs;
Replace with:

Code: Select all

$request = new Request();
if (isset($request->get['route'])) {
       $this->data['breadcrumbs'] = array();
}

if($request->get['route']=='common/home'){
   $this->data['breadcrumbs'] = array();
}else{
   $this->data['breadcrumbs'] = $this->document->breadcrumbs;   
}
Is this correct?

Active Member

Posts

Joined
Tue Apr 07, 2009 1:20 am

Post by Leon » Wed Jul 22, 2009 5:56 pm

Tested my code and it doesn't work at all :p

I tried this:

Code: Select all

		    $request = new Request();
    if (empty($request->get['route'])) {
           $this->data['breadcrumbs'] = array();
    }else{
	    if($request->get['route']=='common/home'){
       $this->data['breadcrumbs'] = array();
    }else{
       $this->data['breadcrumbs'] = $this->document->breadcrumbs;   
    }
	}
And it works well without errors; however, if using seo urls, then the code assumes that get['route'] is empty, so it doesn't display the breadcrumb bar.

Help please :D

Active Member

Posts

Joined
Tue Apr 07, 2009 1:20 am

Post by readyman » Wed Jul 22, 2009 10:56 pm

In layout.tpl where the breadcrumbs appear...

Code: Select all

<?php if(sizeof($breadcrumbs) > 1) { //no breadcrumbs on the homepage ?>
    <div id="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
<?php } ?>
As seen on alreadymade.com

http://www.alreadymade.com
Follow me on twitter.com/alreadymade


User avatar
Global Moderator

Posts

Joined
Wed May 20, 2009 5:16 am
Location - Sydney

Post by Leon » Thu Jul 23, 2009 12:33 am

Thanks for the help readyman.

Your original code screws up my template.

Code: Select all

<div id="breadcrumb">
<?php if(sizeof($breadcrumbs) > 1) { //no breadcrumbs on the homepage ?>
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php }} ?>
    </div>
Is much better :)

Active Member

Posts

Joined
Tue Apr 07, 2009 1:20 am

Post by readyman » Thu Jul 23, 2009 1:00 am

I'm assuming you've got some height or other issue applied where you need to have the breadcrumb div always visible? For best practice, you should hide the element when it's not used, and apply the required spacing on a different element eg. navigation bottom margin or similar.
But if it works already, I guess you won't want to change anything. :)

http://www.alreadymade.com
Follow me on twitter.com/alreadymade


User avatar
Global Moderator

Posts

Joined
Wed May 20, 2009 5:16 am
Location - Sydney

Post by richard » Thu Jul 23, 2009 1:49 am

Hi..

readyman's solution is more appropriate since it is template based therefore much more portable
although in the MVC style, it will be done in the C, in this case since it is done
in the V, you can move it from template to template and not mess with the C
:)

Image a point in time
http://richarrdg.tumblr.com/


New member

Posts

Joined
Wed Jul 08, 2009 2:09 pm

Post by Leon » Thu Jul 23, 2009 2:54 am

Thanks for the advice; it's always good to learn new things.

I've wanted to learn more about php for a while, and now it's summer i have a bit of time and can do so :)

Can you tell me the implications of doing it the way i did?

Cheers

Active Member

Posts

Joined
Tue Apr 07, 2009 1:20 am

Post by readyman » Sat Jul 25, 2009 5:09 am

It's not a big issue, but it helps to keep track of things, otherwise you are rebuilding everytime there's an update.

The implications of editing the core files are:
- You've changed the source, so any submitted files, templates etc, might not work with your changes.
- Your changes will not be included in future upgrades to the core and would mean you are recoding these into an updated core.
- If the changes you are making are to the layout & structure and not data related, then it's best to keep this type of code in the 'view'. Let controller and models handle the data & use the view to control the display.

http://www.alreadymade.com
Follow me on twitter.com/alreadymade


User avatar
Global Moderator

Posts

Joined
Wed May 20, 2009 5:16 am
Location - Sydney
Who is online

Users browsing this forum: Amazon [Bot] and 2 guests