Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Wellwisher on October 13, 2017, 09:45:38 PM

Title: Breadcrumbs: Have the first link say "Home" instead of default forum name.
Post by: Wellwisher on October 13, 2017, 09:45:38 PM
I am trying to have the first link of the breadcrumbs say "Home"

So basically instead of breadcrumbs saying this:

✘ Simple Machines Community Forum >  Customizing SMF >  SMF Coding Discussion > Start new topic

I prefer breadcrumbs to say this:

✔ Home > Customizing SMF > SMF Coding Discussion > Start new topic

Why do this? My forum name is long and it will save screen real estate.  :)
Title: Re: Breadcrumbs: Have the first link say "Home" instead of default forum name.
Post by: Sir Osis of Liver on October 13, 2017, 10:42:58 PM
index.template.php -



// Each tree item has a URL and name. Some may have extra_before and extra_after.
foreach ($context['linktree'] as $link_num => $tree)
{
if ($tree['name'] == $context['forum_name'])
$tree['name'] = 'Home';

echo '
<li', ($link_num == count($context['linktree']) - 1) ? ' class="last"' : '', '>';


Title: Re: Breadcrumbs: Have the first link say "Home" instead of default forum name.
Post by: Wellwisher on October 14, 2017, 12:34:19 AM
@Sir Osis of Liver cheers for the reply, I tested it out on my local, but nothing seems to change. Not sure if I am doing something wrong.

This is my theme code for brumbcrumbs and amended it with your code, I have only added this to my display.template.php as I only want my breadcrumbs showing in post/ thread view:



echo '
<div class="navigate_section">
<ul>';


// Each tree item has a URL and name. Some may have extra_before and extra_after.
foreach ($context['linktree'] as $link_num => $tree)
{
if ($tree['name'] == $context['forum_name'])
$tree['name'] = 'Home';

echo '
<li', ($link_num == count($context['linktree']) - 1) ? ' class="last"' : '', '>';

// Show something before the link?
if (isset($tree['extra_before']))
echo $tree['extra_before'];

// Show the link, including a URL if it should have one.
echo $settings['linktree_link'] && isset($tree['url']) ? '
<a href="' . $tree['url'] . '"><span>' . $tree['name'] . '</span></a>' : '<span>' . $tree['name'] . '</span>';

// Show something after the link...?
if (isset($tree['extra_after']))
echo $tree['extra_after'];

// Don't show a separator for the last one.
if ($link_num != count($context['linktree']) - 1)
echo ' &#187;';

echo '
</li>';
}
echo '
</ul>
</div>';

Title: Re: Breadcrumbs: Have the first link say "Home" instead of default forum name.
Post by: Sir Osis of Liver on October 14, 2017, 12:45:10 AM
Linktree is in index.template.php, it is displayed on all pages, you can't just stick the code in a different template and expect it to work.  It's generally considered to be a bad idea to remove linktree from any pages, but may be possible to do if index template can identify when it's wrapped around display template.  Will have to tinker with it.
Title: Re: Breadcrumbs: Have the first link say "Home" instead of default forum name.
Post by: Sir Osis of Liver on October 14, 2017, 01:13:02 AM
Ok, lower linktree is already in Display.template.php, so you just have to remove upper linktree from index.template. php, like this -



// Show the navigation tree.
// theme_linktree();



Then add upper linktree to Display.template.php -



function template_main()
{
global $context, $settings, $options, $txt, $scripturl, $modSettings;

// Add upper linktree
theme_linktree();

// Let them know, if their report was a success!



Lower linktree is still displayed in message index, you can either remove it in MessageIndex.template.php, or add upper linktree same as you did in Display.template.php.
Title: Re: Breadcrumbs: Have the first link say "Home" instead of default forum name.
Post by: Wellwisher on October 14, 2017, 09:40:27 PM
Tried it but I failed you.  :P

Maybe it's because I made a number of changes in index.template.php and display.template.php so it's not as easy to implement on my end. None-the-less, I appreciate the help @Sir Osis of Liver.

I thought if it's easy to amend the breadcrumbs, I might as well seek some advise here. Turns out I spent more time tinkering with the code then I should have.  ;D

Other people running approved themes will find this advise useful so thank you.

I am gonna take the U.K's "that'll do approch" on this and leave it as is.
From your advise, I am luckily to have got this far. ;D

Title: Re: Breadcrumbs: Have the first link say "Home" instead of default forum name.
Post by: Sir Osis of Liver on October 14, 2017, 11:52:08 PM
Sorry, been offline since last night.  If you can attach your index.template.php and Display.template.php, I'll have a look.
Title: Re: Breadcrumbs: Have the first link say "Home" instead of default forum name.
Post by: Wellwisher on October 15, 2017, 02:02:20 PM
Quote from: Sir Osis of Liver on October 14, 2017, 11:52:08 PM
Sorry, been offline since last night.  If you can attach your index.template.php and Display.template.php, I'll have a look.

Nice, thank you. I have added the files here. *FYI, wear some eye protection goggles*, some of the codes may force you to poke your eyes out. As some codes are really iffy work-arounds.  ;D I have lost all hope.  :P I have kept the files non-edited (before your code sugguestions) so you can keep your sanity.
Title: Re: Breadcrumbs: Have the first link say "Home" instead of default forum name.
Post by: Sir Osis of Liver on October 15, 2017, 04:57:32 PM
Just got on, will take a look.
Title: Re: Breadcrumbs: Have the first link say "Home" instead of default forum name.
Post by: Sir Osis of Liver on October 15, 2017, 05:38:48 PM
 (http://www.thekrashsite.com/pics/eek.gif)  Ok, those files are broken and don't display correctly, but I think I see what you've done wrong with linktree, I'll try to explain it a little better. 

The upper linktree on all pages is in index.template.php, you remove it by doing this -



// Show the navigation tree.
// theme_linktree();



Now you won't see an upper linktree anywhere, but you will see a lower linktree in message index and topic display, it's called by this in both templates -



// Show breadcrumbs at the bottom too.
theme_linktree();



The theme_linktree() function is not repeated in those two files, it's inherited from index.template.php, so you don't have to add it to message index or display template.  You need to do this to restore upper linktree to those two templates -

MessageIndex.template.php



function template_main()
{
global $context, $settings, $options, $scripturl, $modSettings, $txt;

// Add upper linktree
theme_linktree();

echo '
<a id="top"></a>';



Display.template.php



function template_main()
{
global $context, $settings, $options, $txt, $scripturl, $modSettings;

// Add upper linktree
theme_linktree();

// Let them know, if their report was a success!



This will give you upper and lower linktree in both.  Now you can replace your forum name with 'Home' by doing this -

index.template.php




// Each tree item has a URL and name. Some may have extra_before and extra_after.
foreach ($context['linktree'] as $link_num => $tree)
{
if ($tree['name'] == $context['forum_name'])
$tree['name'] = 'Home';

echo '
<li', ($link_num == count($context['linktree']) - 1) ? ' class="last"' : '', '>';



You only have to do it once, as all three templates use the same function, but it's no longer being called in main index, so you won't see it there. 

Best bet would probably be to start out again with clean files.
Title: Re: Breadcrumbs: Have the first link say "Home" instead of default forum name.
Post by: Wellwisher on October 18, 2017, 09:54:47 PM
Roger that, thanks again for your help. I will try it using the default theme again this weekend.   ;D
Title: Re: Breadcrumbs: Have the first link say "Home" instead of default forum name.
Post by: Wellwisher on November 12, 2017, 02:07:01 PM
@Sir Osis of Liver just tried your code with fresh install files/ new database and username (without mods etc), code works! No idea why it wouldn't accept it in my custom theme but I should be able to figure it out from now. Thank you man. FYI you guys ought to add this to 2.1. Some people have long ass names for the forum and just saying "home" is easier for visitors and saves space! TY.  :)