Dynamically generated Navigation Diagram using Custom Fields

Ah, I see a few places where I went wrong.

For one, in the switch statements, when I tried to return answers using echo, I was using parentheses, which work fine in one offs, but apparently cause an error in a function(?). Thanks to the one who edited my first code! I would not have seen that.

So when I changed this:

switch($graphic[0]) {
        case 1:
            return ('<img src="'.get_template_directory_uri().'/img/Zinder-Law-nav-graphic.gif" alt="Our Clients, Their Challenges" width="330" height="299" border="0" usemap="#Gui" />');
            break;
        case 2:
            return ('<img src="'.get_template_directory_uri().'/img/Zinder-Law-nav-graphic_client_challenges.gif" alt="Client Challenges" width="330" height="299" border="0" usemap="#Gui" />');
            break;
        case 3:
            return ('<img src="'.get_template_directory_uri().'/img/Zinder-Law-nav-graphic_our_clients.gif" alt="Our Clients" width="330" height="299" border="0" usemap="#Gui" />');
            break;
        default:
            alert("No setting!");
    };

to this:

switch($graphic[0]) {
    case 1:
        echo '<img src="'.get_template_directory_uri().'/img/Zinder-Law-nav-graphic.gif" alt="Our Clients, Their Challenges" width="330" height="299" border="0" usemap="#Gui" />';
        break;
    case 2:
        echo '<img src="'.get_template_directory_uri().'/img/Zinder-Law-nav-graphic_client_challenges.gif" alt="Client Challenges" width="330" height="299" border="0" usemap="#Gui" />';
        break;
    case 3:
        echo '<img src="'.get_template_directory_uri().'/img/Zinder-Law-nav-graphic_our_clients.gif" alt="Our Clients" width="330" height="299" border="0" usemap="#Gui" />';
        break;                  
    default:
        echo "No setting!";
};

It worked as I was expecting.

Further, I realized I forgot to add the array position to the $graphic string when I tried to use it to compare numbers here, also I was using three equals instead of two:

foreach($navGraphicList as $list) {
    if($list->navDiagram === $graphic){
        print_r(array_values($list->navLocations));
    };
};

So changing it to:

foreach($navGraphicList as $list) {
    if($list->navDiagram == $graphic[0]){
        var_dump($list->navLocations);
    };
};

Allowed me to actually call the correct values.

After I discovered the answer, I was able to quickly finish the code I need:

foreach($navGraphicList as $list) {
    if ($list->navDiagram == $graphic[0]){
        echo '<map name="Gui">';
        foreach($list->navLocations as $map){
            echo $map;
        };
        echo '</map>';
    };
};

Although I found these solutions on my own, I still cannot discover a good answer to my related question of how to add the longer array without adding additional code or values on each page. For now, this array will be two deep instead of three. If anyone can comment with any ideas, I would much appreciate it.