Page 1 of 1

{NAV_SELECTOR:parent_id:selected_id:title}

Posted: Thu 5. Aug 2004, 13:38
by Plauderer
Hi again. Gruess euch!

I added another function which replaces the tag {NAV_SELECTOR} with a <SELECT> box. It takes parent_id (under which the entries from struct shall be displayed), selected_id (this ID will be set as selected) and title (a title / description which will be displayed as first entry) as parameters.

The replacement tag looks like this:
{NAV_SELECTOR:parent_id:selected_id:title}

Here are the functions:

conf.template_default.inc.php

Code: Select all

// navigation selectbox
$template_default["nav_selectbox"]["size"] = 1;
$template_default["nav_selectbox"]["class"] = "selectbox";
Sets size (how many rows) and class (for CSS style) for the SELECT tag.

content.func.inc.php

Code: Select all

// NAV_SELECTOR:parent_id:selected_id:title (by Ch.Kostal, 2004)
if( ! ( strpos($content["all"],'{NAV_SELECTOR')===false ) ) {
    $content["all"] = str_replace('{NAV_SELECTOR}', '{NAV_SELECTOR:0:0:}', $content["all"]);
    $content["all"] = preg_replace('/\{NAV_SELECTOR:(.*?):(.*?):(.*?)\}/e', 'nav_selectbox($content["struct"], "$1", "$2", "$3", $template_default["nav_selectbox"])', $content["all"]);
}

// -------------------------------------------------------------
the function for replacement

front.func.inc.php

Code: Select all

// by Ch.Kostal, 2004 - returns SELECT form element with given structure level
function nav_selectbox ($struct, $parent_id, $selected, $title, $nav_selectbox_struct) {
    $title = ($title == "") ? false : $title;
    foreach ($struct as $key => $value) {
        if ($struct[$key]["acat_struct"] == $parent_id && $key && !$struct[$key]["acat_hidden"]) {
            $temp_struct[ $struct[$key]["acat_id"] ] = $struct[$key];
        }
    }
    if (sizeof($temp_struct)) {
        $option_list = '';
        $option_list = ($title) ? '<option value="-1">' . $title . '</option>' : '';
        foreach ($temp_struct as $key => $value) {
            $option_list .= '  <option ';
            $option_list .= ($key == $selected) ? 'selected ' : '';
            $option_list .= 'value="' . $temp_struct[$key]["acat_alias"] . '">' . $temp_struct[$key]["acat_name"] . "</option>\n";
        }
        $selectbox .= '<select size="' . $nav_selectbox_struct["size"] . '" name="selector" class="' . $nav_selectbox_struct["class"] . '"';
        $selectbox .= " onchange=\"if(this.options[this.selectedIndex].value != -1){ window.document.location.href = '/index.php?' + this.options[this.selectedIndex].value }\">\n";
        $selectbox .= $option_list . "</select>";
        return $selectbox;
    }
    else {
        return '';
    }
}

// -------------------------------------------------------------
I hope some of you find this usefull! :)

Cheers, Plauderer

request

Posted: Thu 5. Aug 2004, 16:11
by mofo
nice, but can you add an online example please?.
thanks a lot..

mofo

Posted: Thu 5. Aug 2004, 17:25
by Plauderer
erm ... ok! :wink:

Suppose you have a site structure likes the following:
ID_0:rootCat
- ID_1:Category 1
- ID_2:Category 2
- ID_3:Category 3
- ID_4:Category 4
- ID_5:Category 5
- ID_6:Category 6
- ID_7:Category 7

Now if you use my script you can use the following:
{NAV_SELECTOR:0:2:Select your Option}

That retrieves you this:
Image

So rootCat (ID_0) is your parent_ID, "Category 2" (ID_2) is selected by default and the select-box has the titlte "Select your Option" which appears as first option (in case no entry is selected).

Now the visitor can use the select-box to navigate through your "main" structure.

Hope that helps.
Plauderer