PDA

View Full Version : Creating a <MENU> template object


Anonymous
11-27-2004, 11:22 AM
Can anyone help me through the process of making a new template object called &lt;MENU>, in which I can create a html menu (which includes other template tags) that will occur on all the template pages?

I don't like the idea of updating five files for every change I make in the menu, and I would really like to have the menu in just one place. I can also think of other templates to create, so this would help me a lot. Or is there any easier way to do this?

Check out Pixelpost installation (and my homemade template) at http://www.baygroove.com/andreas/photos , and you will hopefully understand what I am trying to do.

(note that the template is far from completed - I just discovered Pixelpost yesterday night...)

pixelpunk
11-27-2004, 12:57 PM
Nicely designed that one.

I've tested the easy way and it doesn't seem to work out.

The other way is to create the menu in index.php, it'll work like you want.
Please let me know what the menu should look like (as far as what are the objects you want in it) and I'll show you how it's done and you can expand on it yourself.

// punk

Var uppe och vandrade i somras, åkte ut från Ritsem, apropå stora sjöfallet :)

Baygroove
11-27-2004, 02:07 PM
Hey, thanks. :) I'm planning to post it as a downloadable template once the work is done.

I want the menu to have links to the different areas (photo, browse thumbnails, calendar archive, referers and so on), lined up as they are on the page now. The formatting is made through CSS (in /template/andreas/andreas-style.css), while the structure is very simple, something like this:

&lt;div id="menu">
&lt;a href="index.php">Home&lt;/a>
&lt;a href="&lt;SITE_REFLINK>">Referers&lt;/a>
&lt;a href="&lt;IMAGE_ID>">Permalink&lt;/a>
&lt;a href="&lt;SITE_BROWSELINK>">Thumbnails&lt;/a>
&lt;a href="index.php?x=archivecalendar">Calendar&lt;/a>
&lt;br />
&lt;a href="http://validator.w3.org/check/referer">Valid XHTML&lt;/a>
&lt;a href="http://jigsaw.w3.org/css-validator/check/referer">Valid CSS&lt;/a>
&lt;SITE_RSS_LINK>
&lt;br />
(other template tags go here, depending on which page it is)
&lt;/div>


I also want to make a link to my regular blog (of which this photoblog will be a part), and to a separate page with a contact sheet. Below the menu links (after &lt;SITE_RSS_LINK>), I will put different template tags depending on which page it is. For image, I will put image information (date and category), on the browse page I will put something else - and so on. These will not be included in the index.php menu and because of that, the &lt;/div> for the menu should be in each template rather than in index.php...

This was a bit hard to explain, hope you get the point!

--Andreas (som bor i Porjus, porten till Laponia - bara ett par mil ifrån Stora Sjöfallet) ;)

pixelpunk
11-28-2004, 04:01 PM
Look for, close to the end of the main script, this:

// ################################################## ########################################//
// END - ECHO TEMPLATE

Before that add your menu-object and have it replaced in a template.

$custom_menu = "
&lt;div id='menu'>
&lt;a href='index.php'>Home&lt;/a>
&lt;a href='index.php?x=ref'>Referers&lt;/a>
&lt;a href='index.php?showimage=$image_id'>Permalink&lt;/a>
&lt;a href='index.php?x=browse'>Thumbnails&lt;/a>
&lt;a href='index.php?x=archivecalendar'>Calendar&lt;/a>
&lt;br />
&lt;a href='http://validator.w3.org/check/referer'>Valid XHTML&lt;/a>
&lt;a href='http://jigsaw.w3.org/css-validator/check/referer'>Valid CSS&lt;/a>
&lt;a href='index.php?x=rss'>RSS 2.0&lt;/a>
&lt;br /> * ** *
&lt;/div>
";
$tpl = ereg_replace("&lt;MENU>",$custom_menu,$tpl);

Something like that.
When you add something from the available tags, you need to enter the script's real variable.

Say if you want to include how many photos there are posted, do a search for the template tag &lt;SITE_PHOTONUMBER> and you will most likely find what the variable is called in the script.
$tpl = ereg_replace("&lt;SITE_PHOTONUMBER>",$pixelpost_photonumb,$tpl);

$pixelpost_photonumb in this case.

Add that to your custom menu thing.
$custom_menu = "
&lt;div id='menu'>
&lt;a href='index.php'>Home&lt;/a>
&lt;a href='index.php?x=ref'>Referers&lt;/a>
&lt;a href='index.php?showimage=$image_id'>Permalink&lt;/a>
&lt;a href='index.php?x=browse'>Thumbnails&lt;/a>
&lt;a href='index.php?x=archivecalendar'>Calendar&lt;/a>
&lt;br />
&lt;a href='http://validator.w3.org/check/referer'>Valid XHTML&lt;/a>
&lt;a href='http://jigsaw.w3.org/css-validator/check/referer'>Valid CSS&lt;/a>
&lt;a href='index.php?x=rss'>RSS 2.0&lt;/a>
&lt;br />
$pixelpost_photonumb photos posted!&lt;br />
&lt;/div>
";
$tpl = ereg_replace("&lt;MENU>",$custom_menu,$tpl);


I think you get the hang of it.
Do not use double-quotes ( " ) in here, just single-quotes instead ( ' ) otherwise you get a parse error. If you need a double-quote escape it, \" like that.

In your template just use &lt;MENU> to include it.

// punk

Baygroove
11-30-2004, 01:11 PM
Ok! just tried it, and it works perfectly well. I will definitely be able to continue on my own from here... Thanks a lot for taking the time to explain this! :D

--Andreas