Editing the linktree (preceding link and editing forum title link)

Started by rexusdiablos, January 21, 2010, 06:08:37 PM

Previous topic - Next topic

rexusdiablos

Hi,

SMF 2.0 RC2 - Curve

I want to edit my linktree. I want it to achieve the following:


  • Addition of a preceding fixed link: HOME (home page of site).
  • Editing of the default forum title link: FORUM HOME (home page of forum).

e.g. HOME >> FORUM HOME >> GENERAL CATEGORY >> GENERAL DISCUSSION

I understand that the default forum title link (see No.2 above) can be defined via the admin panel but I don't want to have to amend this. I simply wish to edit the link as it appears in the linktree.

I've looked through the code but I'm fairly unsure where it is that I should begin editing. Any tips or help?

// Show a linktree. This is that thing that shows "My Community | General Category | General Discussion"..
function theme_linktree($force_show = false)
{
global $context, $settings, $options, $shown_linktree;

// If linktree is empty, just return - also allow an override.
if (empty($context['linktree']) || (!empty($context['dont_default_linktree']) && !$force_show))
return;

// Reverse the linktree in right to left mode.
if ($context['right_to_left'])
$context['linktree'] = array_reverse($context['linktree'], true);

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

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

// 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 && !$context['right_to_left'])
echo '&nbsp;&#187;';

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

$shown_linktree = true;
}
"You just can't make this stuff up!" - Alex Jones | www.infowars.com

Arantor

So where does Home link and where does Forum Home link then?

Essentially you will be modifying $context['linktree'] in the sources; it's a numeric array, where
  • is the first item, [1] is the second. The very first item is declared early on, each action adds its own items to the end of it.

    Each item is an array in itself, where ['url'] is the link destination, and ['name'] the text.

rexusdiablos

Quote from: Arantor on January 21, 2010, 06:33:20 PM
So where does Home link and where does Forum Home link then?

I can't tell if that's a rhetorical question or not. If it is, 'HOME' links to /index.php (relative to web root) and 'FORUM HOME' links to /forum (again, relative to web root).

Quote from: Arantor on January 21, 2010, 06:33:20 PM
Essentially you will be modifying $context['linktree'] in the sources;

What specific document is it in the Sources folder?
"You just can't make this stuff up!" - Alex Jones | www.infowars.com

Arantor

It's not a rheatorical question at all. I couldn't tell you where to look at add the code in if i didn't know where it was supposed to go.

Which file depends on what pages this applies to. Every page, including SSI with template header calls?

rexusdiablos

Ah, I where you're coming from.

I want all linktrees to be of the same structure as described in my OP. By this I'm referring to the top and bottom linktrees on every page (e.g. Board.template.php etc.).

Is it not just a case of editing the one file/function?
"You just can't make this stuff up!" - Alex Jones | www.infowars.com

Arantor

No, it isn't, necessarily.

Hence, where should the Home / Forum Home be visible? Would those two links be on every single page, or not? Is there ANY instance where you'd have Home but not Forum Home, for example?

rexusdiablos

Yes, the linktree will appear as described on every single page both top and bottom.

EDIT: I just noticed that many pages simply have a top linktree. That's fine. Wherever there is a linktree I simply want it to be formated as described. I don't want to add new linktrees.

And no, one link will never exist without the other. There will not be any case where I will have a variation of the following (it's consistent):

HOME (linking to overall home page) >> FORUM HOME (linking to forum home) >> Whatever else follows e.g. General Category etc.

I want the linktree to be relative to web root and since /forum is a folder sitting in my web root the FORUM HOME link will always come second in the linktree.

Apologies for complicating my explanation.
"You just can't make this stuff up!" - Alex Jones | www.infowars.com

Arantor

Actually, that doesn't complicate it at all, it simplifies things, sort of.

OK, the master 'Home' one is set up in Load.php:
// Set the top level linktree up.
array_unshift($context['linktree'], array(
'url' => $scripturl,
'name' => $context['forum_name_html_safe']
));


This will set up the forum's name as its text, and the forum base as the destination. Realistically this code needs to become:

// Set the top level linktree up.
array_unshift($context['linktree'], array(
'url' => $scripturl,
'name' => 'Forum Home',
));

array_unshift($context['linktree'], array(
'url' => 'http://mywebsite.com/home',
'name' => 'Home',
));


That will fix your linktree up.

Are you using SSI with template_header() ?

rexusdiablos

That works perfectly. So much thanks for your expertise and time.

I will be using SSI but I haven't dabbled with it in any way yet. I'm not sure why I'd use SSI with template_header(). Can you give me an example?
"You just can't make this stuff up!" - Alex Jones | www.infowars.com

Arantor

OK, let's say that on your homepage you want to reuse the same header and footer as the forum, so you only have one set of theme files, and want to share them equally throughout your site, not only the forum. Then you'd call template_header() to call the forum header into nonforum pages.

rexusdiablos

That's an apt example. Based on your explanation I seem to be doing the reverse:

I'm not applying the forums header to the rest of the site but I am applying a universal header to all pages of the site including forum pages.

For example, I've applied the universal header to my forum pages simply by adding the following code above the wrapper of index.template.php:

include($_SERVER['DOCUMENT_ROOT']."/include/header.php");

Now that you've mentioned it, I'm considering using an SSI footer and applying it universally to the site. It might list the five most recent posts or members currently online. It would be fairly nifty to be able to display those details on non-forum pages such as /index.php or /blog (Wordpress Blog). For clarity, /forum and /blog are both in the webroot.

On a sidenote, I'll be using the linktree concept for all pages of my site though the linktrees of non-forum pages will not be leveraged by SMF in any way. Sure, they'll look the exact same to the end-user which is the desired effect, but it's something I'll build manually without any dependence on the linktree relevant files of /forum.

e.g. HOME >> BLOG HOME >> SOME CATEGORY >> SOME ARTICLE



"You just can't make this stuff up!" - Alex Jones | www.infowars.com

Arantor

Just ensure that SSI.php is included as the first statement on the page, then call template_footer() in the appropriate place.

If you decide to use a single template, and you use SMF's (for which, make sure SSI.php is included, then template_header()) you may need to mess with $context['linktree'] to get it to be right, since template_header also calls the breadcrumb trail IIRC.

rexusdiablos

"You just can't make this stuff up!" - Alex Jones | www.infowars.com

cowboytns

Quote from: Arantor on January 21, 2010, 09:49:45 PM
Just ensure that SSI.php is included as the first statement on the page, then call template_footer() in the appropriate place.

If you decide to use a single template, and you use SMF's (for which, make sure SSI.php is included, then template_header()) you may need to mess with $context['linktree'] to get it to be right, since template_header also calls the breadcrumb trail IIRC.

Okay so I guess I need to mess with "$context['linktree']"  I am doing just as you suggest I have a homepage that I have set up to look like my forum and now I want only "home" to show up when I am on that page.  I want the "forum home" to go away.

Soon I will be adding aditional pages, once they are done how will I edit the linktree so that they appear?  For example I will be adding a news page so the linktree will need to look like this: Home >> News.

I adjusted the code in load.php per your previous post to include "home" in the linktree.

If it helps here is the code for my homepage:
<?php

// Load up SSI
require(dirname(__FILE__) . '/SSI.php');

// Set up the page title
$context['page_title'] = 'Brainmush.net';
$context['page_title_html_safe'] = 'Brainmush.net';

// Set up linktree
$context['linktree'][] = array(
  
'url' => $_SERVER['PHP_SELF'],
  
);

// Initialize the template
template_init();

// Load up the headers
template_header();

// Load your template function
template_main();

// Load the template footer
template_footer();

// Set up the main template
function template_main()
{
global $context$settings$options$scripturl$txt$modSettings;

echo '

<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="left" class="catbg">Brainmush.net Is Going To Rock!</td></tr>

<tr>
     <td>
         <p align="justify"><b>Welcome to Brainmush.net.  Currently this site is under construction.  However, some of the ideas that we are planning are described here.  Take a look and let us know what you think in the forums.</b></p>
     </td>
</tr>

</table><br>'
;

echo 
'
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="top">
<td width="50%">
<table cellpadding="2" cellspacing="0" border="0" align="top">
<tr>
     <td width="50%" class="catbg">Forum
     </td>
</tr>
<tr>
     <td width="50%">
          <p align="justify">Eventually all of the topics from the old forum will be moved to the new forum.  There are hopes that we will be able to provide topic previews on this webpage on the forum discussions.</p>
     </td>
</tr>
<tr>
     <td width="50%" class="catbg">News
     </td>
</tr>
<tr>
     <td width="50%">
          <p align="justify">The news area gives us a place to combine headlines from several news sources that our contributors prefer.  All contributors are encouraged to let the site administartors know of any news sources that they would like to see on the site.</p>
     </td>
</tr>
<tr>
     <td width="50%" class="catbg">The Reading Room
     </td>
</tr>
<tr>
     <td width="50%">
          <p align="justify">The reading room will have two sections:  book reviews and book discussions.  The book reviews section will contain books reviewed by site contributors and possibly guests.  Hopefully we will be able to figure out how to sort the book reviews by several parameters: author, title, subject, type, etc.  There will be a box at the bottom of the page for others to contribute a book review.  All reviews will not be posted until reviewd by the site administrators.</p>
     </td>
</tr>
</table>
</td>

<td width="8">&nbsp;</td>

<td width="50%" align="top">
<table cellpadding="2" cellspacing="0" border="0" align="top">
<tr>
     <td width="50%" class="catbg">TNA Brewing
     </td>
</tr>
<tr>
     <td width="50%">
          <p align="justify">This area of the site will be a dedication to one of the past times of the site founders, home brewing.  This will be a brief history of all of the brews that they have brewed throughout the history of their "brewery".</p>
     </td>
</tr>
<tr>
     <td width="50%" class="catbg">About Brainmush
     </td>
</tr>
<tr>
     <td width="50%">
          <p align="justify">Here information will be provided on the background for Brainmush.net.  Also there may be a place to briefly introduce the site founders and/or contributors.  This way users of the site may get a better feel for where an author of an article is coming from.</p>
     </td>
</tr>
</table>
</td>
</table>'
;
}



?>


By the way I am using SMF 2.0 RC2 - Luxemburgues theme

Thanks

roshaoar

Hello Arantor,

This tweak worked great for every section of my forum except the homepage. On the homepage the URL is right, but instead of showing the text I'd like it insists on showing the forum title rather that what's set in load.php. So it ends up as forum home >> forum home... which is of course isn't right.

I'm relatively new to SMF but I do have various mods installed, including responsive curve, modify linktree, show recent topics, optimus brave and Pretty URLs. As far as I know these are the only ones that might affect this. Are you aware of any possible conflict with these in this tweak, does anything ring a bell?

Alternatively, can you tell me what the lines of php should be to get the same linktree as working everywhere else?

Alternatively can you suggest any files I should look at to copy the master linktree code into the index template, ie to correct it?

Thank you for your time,

-Johan


roshaoar


roshaoar

Just for the record, I solved my query. It was due to the optimus prime plugin, it sets a value for a specific array number. On \Sources\Subs-Optimus.php

$context['linktree'][0]['name'] = $mbname;

Comment this out and all is good



Advertisement: