News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

php include().. include site <head> area on all forum pages.

Started by 8105, May 21, 2007, 04:45:03 PM

Previous topic - Next topic

8105

Is there a way to include the <head> area of my site to all of the forum pages? So it looks like it belongs with the rest of my site.

Thanks.

Kays

Yes, create a seperate header.php file for it. And then include it in the top of all of your site pages and as well as in Index.template.php in the theme you're using.

There's less maintanence with just one header file to change. :)

Edit:
Don't include the <head> stuff, that should be unique for each page. Just what's below the <body> tag which is where the banner is located.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

8105

Lets make sure we're on the same level :)

I have a include_nav.html file that php include() calls, so it's the same on each of my pages, eg: <?php include("include_nav.html"); ?>

So could I add <?php include("include_nav.html"); ?> into the forum script to make it apear on all the forum pages?

Here's an example of what I am trying to achieve: http://pc-uk.110mb.com/smf_pc-uk_layout.php

(Everything above that forum image is in <?php include("include_nav.html"); ?> )

Rudolf

Yeah you would have to include it in the index.template.php somewhere in the template_main_above() function. The actual location depends on your theme.
You don't need the php tags, of course.
I will update all my mods in the next few weeks. Thanks for your patience.

SVG-Collapse (you need an SVG compliant browser)

Kays

QuoteSo could I add <?php include("include_nav.html"); ?> into the forum script to make it apear on all the forum pages?

If it's not in the same folder as your boards, you'll need to change the path also.

Did a view source of the link you provided. If the <head> info is a part of the include then you'll have to modify it since SMF has it's own most of which is required. I also see that you've got a style switcher. Are you planning on using it on the boards some how?

I don't think you can just drop it in. I think you're going to have to seperate the <head> from the header

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

8105

The style switcher will be tricky to implement into the forum so it would be easier to make another includes file with the style switcher disabled.

This is the contents of my include_nav.html file: http://pc-uk.110mb.com/include_nav.html

and my copyright: http://pc-uk.110mb.com/include_copyright.html (not much there)

I'm not exactly sure where include it in the code though. but then again, I think my include_nav file will need editing.

Here's the code for the theme i'm using:


// The main sub template above the content.
function template_main_above()
{
   global $context, $settings, $options, $scripturl, $txt, $modSettings;

   // Show right to left and the character set for ease of translating.
   echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '><head>
   <meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
   <meta name="description" content="', $context['page_title'], '" />', empty($context['robot_no_index']) ? '' : '
   <meta name="robots" content="noindex" />', '
   <meta name="keywords" content="PHP, MySQL, bulletin, board, free, open, source, smf, simple, machines, forum" />
   <script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/script.js?fin11"></script>
   <script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
      var smf_theme_url = "', $settings['theme_url'], '";
      var smf_images_url = "', $settings['images_url'], '";
      var smf_scripturl = "', $scripturl, '";
      var smf_iso_case_folding = ', $context['server']['iso_case_folding'] ? 'true' : 'false', ';
      var smf_charset = "', $context['character_set'], '";
   // ]]></script>
   <title>', $context['page_title'], '</title>
   <link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/style.css?fin11" />
   <link rel="stylesheet" type="text/css" href="', $settings['default_theme_url'], '/print.css?fin11" media="print" />';

   /* Internet Explorer 4/5 and Opera 6 just don't do font sizes properly. (they are big...)
      Thus, in Internet Explorer 4, 5, and Opera 6 this will show fonts one size smaller than usual.
      Note that this is affected by whether IE 6 is in standards compliance mode.. if not, it will also be big.
      Standards compliance mode happens when you use xhtml... */
   if ($context['browser']['needs_size_fix'])
      echo '
   <link rel="stylesheet" type="text/css" href="', $settings['default_theme_url'], '/fonts-compat.css" />';

   // Show all the relative links, such as help, search, contents, and the like.
   echo '
   <link rel="help" href="', $scripturl, '?action=help" target="_blank" />
   <link rel="search" href="' . $scripturl . '?action=search" />
   <link rel="contents" href="', $scripturl, '" />';

   // If RSS feeds are enabled, advertise the presence of one.
   if (!empty($modSettings['xmlnews_enable']))
      echo '
   <link rel="alternate" type="application/rss+xml" title="', $context['forum_name'], ' - RSS" href="', $scripturl, '?type=rss;action=.xml" />';

   // If we're viewing a topic, these should be the previous and next topics, respectively.
   if (!empty($context['current_topic']))
      echo '
   <link rel="prev" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=prev" />
   <link rel="next" href="', $scripturl, '?topic=', $context['current_topic'], '.0;prev_next=next" />';

   // If we're in a board, or a topic for that matter, the index will be the board's index.
   if (!empty($context['current_board']))
      echo '
   <link rel="index" href="' . $scripturl . '?board=' . $context['current_board'] . '.0" />';

   // Output any remaining HTML headers. (from mods, maybe?)
   echo $context['html_headers'], '
</head>
<body>';

   // The logo, user information, news, and menu.
   echo '
   <table cellspacing="0" cellpadding="0" border="0" align="center" width="95%" class="tborder">
      <tr style="background-color: #ffffff;">
         <td valign="middle" align="left"><img src="', !empty($settings['header_logo_url']) ? $settings['header_logo_url'] : $settings['images_url'] . '/smflogo.gif', '" alt="" /></td>
         <td valign="middle">';

   // If the user is logged in, display stuff like their name, new messages, etc.
   if ($context['user']['is_logged'])
   {
      echo '
            ', $txt['hello_member'], ' <b>', $context['user']['name'], '</b>', $context['allow_pm'] ? ', ' . $txt[152] . ' <a href="' . $scripturl . '?action=pm">' . $context['user']['messages'] . ' ' . ($context['user']['messages'] != 1 ? $txt[153] : $txt[471]) . '</a>' . $txt['newmessages4'] . ' ' . $context['user']['unread_messages'] . ' ' . ($context['user']['unread_messages'] == 1 ? $txt['newmessages0'] : $txt['newmessages1']) : '', '.';

      // Are there any members waiting for approval?
      if (!empty($context['unapproved_members']))
         echo '<br />
            ', $context['unapproved_members'] == 1 ? $txt['approve_thereis'] : $txt['approve_thereare'], ' <a href="', $scripturl, '?action=viewmembers;sa=browse;type=approve">', $context['unapproved_members'] == 1 ? $txt['approve_member'] : $context['unapproved_members'] . ' ' . $txt['approve_members'], '</a> ', $txt['approve_members_waiting'];

      // Is the forum in maintenance mode?
      if ($context['in_maintenance'] && $context['user']['is_admin'])
         echo '<br />
            <b>', $txt[616], '</b>';
   }
   // Otherwise they're a guest - so politely ask them to register or login.
   else
      echo '
            ', $txt['welcome_guest'];

   echo '
            <br />', $context['current_time'], '
         </td>
      </tr>
      <tr class="windowbg2">
         <td colspan="2" valign="middle" align="center" class="tborder" style="border-width: 1px 0 0 0; font-size: smaller;">';

   // Show the menu here, according to the menu sub template.
   template_menu();

   echo '
         </td>
      </tr>';

   // Show a random news item? (or you could pick one from news_lines...)
   if (!empty($settings['enable_news']))
      echo '
      <tr class="windowbg2">
         <td colspan="2" height="24" class="tborder" style="border-width: 1px 0 0 0; padding-left: 1ex;">
            <b>', $txt[102], ':</b> ', $context['random_news_line'], '
         </td>
      </tr>';

   echo '
   </table>

   <br />
   <table cellspacing="0" cellpadding="10" border="0" align="center" width="95%" class="tborder">
      <tr><td valign="top" style="background-color: #ffffff;">';
}

Kays

If the style switcher only controls the top menu then it might not be a problem.

What I would do is this:

First remove all of the javascript for the menu and place it in a seperate file. In fact you can combine your other .js files with this one so there's only one to link to. Then add the links to the .js file(s) the the <head> of index.template.php as well as the links to the .css files for the style switcher. You might have to copy over that bit of css also.

Now in your header, remove everything after the first <table> tag after <body> right up to the </table> after the google ad code and place it in a seperate file. Call it subheader.php and place it as an include in the area you removed it from in the header. Now this can be included into your Index.template.php.

Then if you just want to replace the SMF logo at the top. Replace this:

   // The logo, user information, news, and menu.
   echo '
   <table cellspacing="0" cellpadding="0" border="0" align="center" width="95%" class="tborder">
      <tr style="background-color: #ffffff;">
         <td valign="middle" align="left"><img src="', !empty($settings['header_logo_url']) ? $settings['header_logo_url'] : $settings['images_url'] . '/smflogo.gif', '" alt="" /></td>
         <td valign="middle">';


with this:

   // The logo, user information, news, and menu.
   echo '
   <table cellspacing="0" cellpadding="0" border="0" align="center" width="95%" class="tborder">';

  include("submenu.php");

echo '
  <tr style="background-color: #ffffff;">
    <td>';


Do change the path to submenu.php to the folder it is in.

This does leave that member box there . If you want to remove it, the script is well commented and you'll need to remove that last echo in what I posted.

Good luck. :)


If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

8105

Quote from: Kays on May 21, 2007, 10:22:31 PM
First remove all of the javascript for the menu and place it in a seperate file. In fact you can combine your other .js files with this one so there's only one to link to. Then add the links to the .js file(s) the the <head> of index.template.php as well as the links to the .css files for the style switcher. You might have to copy over that bit of css also.

I'm not quite sure what you mean by that bit.

Quote from: Kays on May 21, 2007, 10:22:31 PM
Now in your header, remove everything after the first <table> tag after <body> right up to the </table> after the google ad code and place it in a seperate file. Call it subheader.php and place it as an include in the area you removed it from in the header. Now this can be included into your Index.template.php.

The part your talking about here is already in an includes file, are you saying I have to create another includes inside of another?

and you told me to name it as subheader.php, and in the code its says "submenu.php". is that just a typo?, sorry.

Kays

Under the <head> and after the links, there's a bunch of javascript from DynamicDrive which controls one of the menus. That needs to be added to Index.template. the best way to do it is to place it in a seperate .js file and link to it rather than having all of the code on the page. You can also place the code for all the.js files into a single file. Because right now you've got two already.


<script type="text/javascript" src="/scripts/styleswitcher.js"></script>
<script type="text/javascript" src="/scripts/showhide.js"></script>


This needs to be added to Index.template.php

<link rel="stylesheet" type="text/css" href="style.css" title="green">
<link rel="alternate stylesheet" type="text/css" href="blue.css" title="blue">
<link rel="alternate stylesheet" type="text/css" href="red.css" title="red">
<link rel="alternate stylesheet" type="text/css" href="vista.css" title="vista">
<link rel="alternate stylesheet" type="text/css" href="pink_lightening_pcuk.css" title="pink_lightening_pcuk">
<link rel="alternate stylesheet" type="text/css" href="flash_menu.css" title="flash">


You do need to change the paths in the above to where those files are located.

Then this also needs to be added. It could also be added to a style sheet instead. (without the <style> tags)


<style type="text/css">

#popitmenu{
position: absolute;
background-image: url(images/ts_bg.jpg);
border:1px silver;
font: normal 12px Verdana;
line-height: 18px;
z-index: 100;
visibility: hidden;
}

#popitmenu a{
text-decoration: none;
padding-left: 6px;
color: #CCCCCC;
display: block;
}

#popitmenu a:hover{ /*hover background color*/
background-color: #333333;
}

</style>


QuoteThe part your talking about here is already in an includes file, are you saying I have to create another includes inside of another?

Yes, because basically that's all that you need. You can't include the whole header because it would probaly break the html in the boards and possibly other things. What you've got by doing it this way is two or three blocks of code which you can easily copy over to a new version of the skin when the boards get updated.

Quoteand you told me to name it as subheader.php, and in the code its says "submenu.php". is that just a typo?,

Ooops, my mistake.

I hope this doesn't confuse you too much. Just do it one step at a time and test it. One thing to watch out for is to make sure that  php tags and/or echos are properly closed on the code you're copying over and that they are started again after. Basically, watch the syntax.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

8105

Ok, the .js files are done (but seperate, not sure how to put them all into one).

The CSS for the menus didn't play well in an external stylesheet (maybeI made an error because I havn't had enough sleep) so I left it how it is. will that still work out?

and for the header part, is this what you wanted me to make the includes subheader.php:

<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#333333">
  <tr>
    <td height="26" colspan="3" background="images/myPS_01.gif"><div align="center" id="links"><a href="index.php" title="Take me back home!">home</a> | <a href="pc_repair.php" title="Get your computer fixed, cheap!">pc repair</a> | <a href="graphic_design.php" title="Graphics, logos, banners and more!">graphic design</a> | <a href="web_design.php" title="Web design and development. Cheap!">web design</a> | <a href="tools.php" title="Free web tools, try them out!">free tools</a> | <a href="about.php" title="yep, all about us!">about us</a> | <a href="contact.php" title="Whatever your needs, contact us!">contact us</a> | <a href="faq.php" style="cursor: help" title="Frequently Asked Questions">FAQ</a> | <a href="#" onMouseover="showmenu(event,linkset[0], '180px')" onMouseout="delayhidemenu()">more&nbsp;</a></div></td>
  </tr>
 
  <tr>
    <td height="30" colspan="2"><div align="left">&nbsp;<a href="#">sign up or  login</a> <img src="images/login.gif" width="12" height="12"></div></td>

    <td height="30" colspan="2"><div align="right"><img src="images/theme_p.gif" width="12" height="12"> <a href="blue.css" onClick="setActiveStyleSheet('blue'); return false;">blue</a>&nbsp;<a href="style.css" onClick="setActiveStyleSheet('green'); return false;">green</a>&nbsp;<a href="red.css" onClick="setActiveStyleSheet('red'); return false;">red</a>&nbsp;<a href="#" onMouseover="showmenu(event,linkset[1], '180px')" onMouseout="delayhidemenu()">more&nbsp;</a></div></td>
  </tr>
  <tr>
    <td width="302" height="159" id="image1"></td>
    <td width="248" height="159" id="image2"></td>
    <td width="250" height="159" id="image3"></td>
  </tr>
    <tr>
    <td height="40" colspan="3"><div align="center">
      <script type="text/javascript"><!--
google_ad_client = "pub-4067313188232985";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al_s";
google_ad_channel = "";
google_color_border = "333333";
google_color_bg = "333333";
google_color_link = "CCCCCC";
google_color_text = "000000";
google_color_url = "008000";
//--></script>
      <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
    </div></td>
  </tr>
  </table>


and I might need to know exactly where to put all this in Index.template.php

Your help is highly appreciated.

Kays

Hi, again. :)

QuoteOk, the .js files are done (but seperate, not sure how to put them all into one).

Just copy all of the seperate scripts into one page. Not a big deal if you don't.

QuoteThe CSS for the menus didn't play well in an external stylesheet (maybeI made an error because I havn't had enough sleep) so I left it how it is. will that still work out?

You'll need to add that to Index.template.php then. That's for one of the menus.

Quoteand for the header part, is this what you wanted me to make the includes subheader.php

Ok, that needs to be a php page with that html being in an echo.


<?php
echo '
   Your html here'
;
?>


Since you've included the <table> tag the best place to up it would be right under the <body> tag find this:

echo '
<div class="tborder" ', $context['browser']['needs_size_fix'] && !$context['browser']['is_ie6'] ? ' style="width: 100%;"' : '', '>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="catbg" height="32">';


And change it to:

echo '
<div class="tborder" ', $context['browser']['needs_size_fix'] && !$context['browser']['is_ie6'] ? ' style="width: 100%;"' : '', '>';

  include("submenu.php:);

  echo '
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="catbg" height="32">';


This wll place it above the SMF logo now.

As for the footer, just place the code for it straight in the footer area in Index.tmplate.php. "function template_main_below()"

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

8105

Quote echo '
<div class="tborder" ', $context['browser']['needs_size_fix'] && !$context['browser']['is_ie6'] ? ' style="width: 100%;"' : '', '>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="catbg" height="32">';

I can't find that anywhere  :( lol

Kays

That was taken from the default theme. Right after the <body> tag, there should the start of the main table or div. It should go in there. if it's a table the it should go after the first <tr><td>.

If you can't find it, post from <body> to about 20 lines down.

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

8105

It wont let me edit the default theme, "core" (there's no option to do so).

So i'm using the Classic YaBB SE Theme. A few posts up, is the index.template.php  source for it: http://www.simplemachines.org/community/index.php?topic=172517.msg1100652#msg1100652

Kays

Right, forgot about that. try placing the include right under:

<body>';


If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

8105


Kays


If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods


Kays

That should be a server path. I don't thiik that works.

Try: /folder/subheader.php


If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods


Advertisement: