Re: Need help with an if statement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Yikes...<font>? that's been deprecated since the turn of the century!

do it with css...

html
<ul>
<li>item 1</li>
<li class="selected">item 2</li>
<li>item 3</li>
</ul>

css:

ul li { background-image: url("/img/arrow-off.png"); color: gray; }
ul .selected { background-image: url("/img/arrow-on.png"); color: red; }

http://www.w3.org/TR/CSS21/colors.html#propdef-background-image

The real question here though is looping through your menu items or
"nodes" in your tree (unordered list)...you'll need to read up on DOM
in php5 or domxml in php4.

I have broken down my page into libraries, for example, my menu.php is
included at the top of every page, and loops through the tree,
checking for whatever condition (in my case I check the current url
against the anchor href for every list item, and if it's equal, then I
dynamically set the class="selected" on the item (parent of anchor),
which can turn it blue, and add an arrowon.png (this part should be
taken care of with css, so you can easily redesign it without changing
your code.

<?php

function selectMenuItem()
{
        global $htdocs;
        global $uri;
        $uri = getenv('REQUEST_URI');

        $dom = new DOMDocument;
        #xhtml fragment which contains the menu
        $dom->load("$htdocs/xml/menu.xml");
        $xpath = new DOMXPath($dom);

        #uses xpath query to find anchors with parent of list item
        $nodes = $xpath->query("//a[parent::li]");

        foreach ($nodes as $node)
        {
                $attr = $node->getAttribute('href');

                if($attr == $uri)
                {
                        $node->setAttribute('class', 'selected');
                }
        }

        #print $dom->saveXML(); #prepends xml declaration and breaks
in IE6 if not the first line.
        print $dom->saveHTML();
}

You can read more about dom with php here: http://www.php.net/dom

Be aware, that you can decorate the heck out of your class/id with
css, an unordered list can look like a set of tabs if needed.

On 4/23/06, Pub <pub@xxxxxxxxxxxxx> wrote:
> Hello,
>
> I am really new to all this and I am really hoping I can get some
> help PLEASE...
> I am making a website with x-cart which uses PHP and Smarty templates.
>
> I need to make an " if " statement that puts a little arrow gif in
> front of the link that is clicked on! make any sense?
>
> In other words:
>
>     item 1 (not selected)
>     item 2 (not selected)
>  > item 3 (selected)
>     item 4 (not selected)
>
> This is what I have now, but I don't know what to call my {if ?????}
>
> {if ?????}<A href="{?????}"><FONT class="buttontextonly"><IMG
> src="{$ImagesDir}/arrow.gif" width="9" height="7" border="0"
> align="abstop">{$menu_content}</FONT></A>
> {else}
> <FONT class="VertMenuTitle">{$menu_content}</FONT>
> {/if}</TD>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>


--
Anthony Ettinger
Signature: http://chovy.dyndns.org/hcard.html

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux