views:

88

answers:

2

Hi,

Need help with my simple PHP menu. I'd like to have something like that: when child elements < 6 display one column if > 6 display two columns. Any advices how to make it?

Regards

A: 

If sub menu contains more than 6 links I like submenu looks like:

Link
Link
Link
Link

If more than 6 links:

Link Link
Link Link
Link Link

I'm using WP, just need advice how to make it.

Andrzej
and WP means WordPress?
Carlos Lima
Carlos, yes, WordPress blog. I built custom drop down menu, but don't know how to make it as I want :)
Andrzej
A: 

Here's the basic idea, you can adapt it to work with a table:

if (count($childs) < 6)
{
    foreach ($childs as $child)
    { 
        echo htmlspecialchars($child)."<br>";
    }
}
else
{
    for ($n=0;$n<count($childs);$n++)
    {
        echo htmlspecialchars($child)." ";
        if ($n%2) echo "<br>";
    }
}

For a table:

if (count($childs) < 6)
{
    // Single row
    echo "<tr>";
    foreach ($childs as $child)
    { 
        echo "<td>".htmlspecialchars($child)."</td>";
    }
    echo "</tr>";
}
else
{
    // Multiple row
    echo "<tr>";
    for ($n=0;$n<count($childs);$n++)
    {
        echo "<td>".htmlspecialchars($child)."</td>";
        if ($n%2) echo "</tr><tr>";
    }
    echo "</tr>";
}

There are other ways.

Ast Derek
Thanks for advice! Damn, I tried to make it good way, but my code was...a bit messy :)
Andrzej