English 中文(简体)
PHP 修复功能,将站点导航作为密封清单,但无必要菜单
原标题:PHP recursive function, to create site navigation as nested list, but without unnecessary menu items

I really dig the idea of using a recursice function to build my site menus but I am having a problem and have been banging my head for ages now. I need my menu function to return a nested list but I dont want non-active irelevent elements of the tree to be displayed.

详情。 我有一个MySql数据库,有一个表格,称为菜单,用于储存所有通常领域的所有物品(目标、链接、文字、所有权等),以及每个项目的独一无二的影子,而重要的是是亲子。

这完全需要辩论,例如,在XML档案中储存这些信息会比较容易?

例如,这里就是一个例子,所有要素都显示:

<ul>
    <li><a href="1.html">link 1</a>
        <ul>
            <li><a href="1-1.html">link 1-1</a>
            <li><a href="1-2.html">link 1-2</a>
        </ul>
    </li>
    <li><a href="2.html">link 2</a>
        <ul>
            <li><a href="2-1.html">link 2-1</a>
            <li><a href="2-2.html">link 2-2</a>
        </ul>
    </li>
    <li><a href="3.html">link 3</a></li>
</ul>

但是,如果现在的网页是1-2.html,那么我就希望这样作:

<ul>
    <li><a href="1.html">link 1</a>
        <ul>
            <li><a href="1-1.html">link 1-1</a>
            <li><a href="1-2.html">link 1-2</a>
        </ul>
    </li>
    <li><a href="2.html">link 2</a></li>
    <li><a href="3.html">link 3</a></li>
</ul>

显然,我将把身份证或现有网页的名称传给Mendu公司。

Any ideas anyone? I have been banging my head against a wall for some time now :-)

问题回答

这是我完整的方法,数据集有一页的影子、一张母子、一个链接(链接)和一个标题;希望能够帮助。

function make_nav($current_page_id)
{
    nav_rec(0, $current_page_id, constant( SITE_URL ), 0);
}

function nav_rec($page, $current_page_id, $link, $level)
{   
    if (!$page)
    {
        $page = array();
        $page[ page_id ] =   0 ;
    }
    else
    {
        ?><a class="nav-link nav-level-<?= $level ?>" href="<?= $link ?>"><?= $page[ title ] ?></a><?
    }

    // Checks for the subpages from this page.  
    $page_q = "
        SELECT id AS page_id, parent_id, permalink, page_title AS title 
        FROM ".constant( MYSQL_PREFIX )."pages 
        WHERE `page_type` =  page 
        AND `in_nav` =  1 
        AND `status` =  published 
        AND `is_deleted` =  0 
        AND `parent_id` =  ".$page[ page_id ]." ";

    if ($page_rs = mysql_query($page_q))
    {
        if (mysql_num_rows($page_rs))
        {
            while($page = mysql_fetch_assoc($page_rs))
            {
                nav_rec($page, $current_page_id, $link . $page[ permalink ]. / , $level+1);
            }
        }
        else
        {
            $level = 0;
        }
    }
    else
    {
        $level = 0;
    }
}




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签