We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Structure - Help with modified main_nav, exclude_status not working

Development and Programming

dreamworld's avatar
dreamworld
25 posts
16 years ago
dreamworld's avatar dreamworld

I’ve been at this all afternoon but with no luck. I just can’t get the exclude_status function to work within this modified ‘main_nav’ from another post, I added the ‘exclude_status’ to this, I’m not getting any php errors when rendering the page out.

function nav_main() {
    global $DB, $IN, $PREFS, $TMPL;
    
    // Retrieve status labels to exclude
    // break apart string at pipe chars and build array
    $exclude_status = $TMPL->fetch_param('exclude_status');
    $exclude_status_list = split("\|", strtolower($exclude_status));
    
    // get site pages data
    $site_pages = $PREFS->core_ini['site_pages'];
    // get current uri path
    $uri = $IN->URI;
    
    // get current entry id
    $entry_id = array_search("/", $site_pages['uris']);
    // get node of the current entry
    $node = 0; //$start_node = $entry_id ? $this->nset->getNode($entry_id) : false;
    
    // node does not have any structure data we return nothing to prevent errors
    if ($node === false && ! $entry_id) {
        return '';
    }
    
    // if we have an entry id but no node, we have listing entry
    if ($entry_id && ! $node) {
        // get entry's parent id
        $pid = $this->get_pid_for_listing_entry($entry_id);
        
        // get node of parent entry
        // because we will be showing nav sub from its view point
        $node = $start_node = $this->nset->getNode($pid);
    }
        
    // if we are on a root that is a leaf
    // no sub nav to return
    if ($node && $node['isLeaf'] && $node['depth'] == 0) {
        return '';
    }
    
    if ($node['isLeaf'] && $node['depth'] > 1) {
        // we are on a child leaf past the root level
        // so we use the parent as the starting point for the sub nav
        $start_node = $this->nset->getNode($node['parent_id']);
    }
    
    //print_r($start_node);die;
    
    // get siblings
    $where = 'node.parent_id = ' . ($start_node['depth'] ? $start_node['parent_id'] : $start_node['id']);
    // get children
    $where .= ' OR node.parent_id = ' . $start_node['id'];
    
    $entry_depth = $start_node['depth'] ? $start_node['depth'] : 1;
      
    // get structure data from DB            
    $sql = "SELECT node.*,
                (COUNT(parent.entry_id) - 1) AS depth,
                ((COUNT(parent.entry_id) - 1) - $entry_depth) AS subDepth,
                if((node.rgt - node.lft) = 1,1,0) AS isLeaf,
                expt.title
            FROM exp_structure AS node
            INNER JOIN exp_structure AS parent
                ON node.lft BETWEEN parent.lft AND parent.rgt
            INNER JOIN exp_weblog_titles AS expt
                ON node.entry_id = expt.entry_id
            WHERE parent.lft > 1
            GROUP BY node.entry_id
            ORDER BY node.lft";
    $result = $DB->query($sql);
    
    
    // check how many entries at subDepth 0
    $num = 0;
    foreach ($result->result as $entry) {
        if ($entry['subDepth'] == 0) {
            $num++;
        }
    }
    
    // if we only have 1 subDepth 0 entry and it has children
    // then we just show the children
    if ($num === 1 && $result->num_rows > 1) {
        unset($result->result[0]);
        foreach ($result->result as &$entry) {
            $entry['subDepth'] -= 1;
        }
    }
     // Remove anything to be excluded from the results array
    foreach ($result->result as $key => $entry_data) {
        if( in_array( strtolower($entry_data['status']), $exclude_status_list) ) {
            unset($result->result[$key]);
        }
    }
    
        $html = '<ul id="navigation">';
    $prev_subDepth = false;
    $ul_open       = false;
    $i= 0;
    
    foreach ($result->result as $entry) {    
        if($prev_subDepth == $entry["subDepth"]  AND $prev_subDepth != false){
            $html .= "</li>";
        }
        
        if($entry["subDepth"]  > $prev_subDepth  and $i >0){
            $html .= '<ul>';
        }
        
        if($entry["subDepth"]  < $prev_subDepth  and $i >0){
            $x = $prev_subDepth - $entry["subDepth"];
            for($y=0;$y<$x;$y++){
                $html .= '</li></ul>';
            }
        }
        
        // out entry uri of this loop instance
        $euri = $site_pages['uris'][$entry['entry_id']];
        // current page's parent uri
        $puri = $node['parent_id'] ? $site_pages['uris'][$node['parent_id']] : '';
        
        $here = '';
        if ($euri === $puri) {
            $here = ' parent_here';
        } else if ($uri === $euri) {
            $here = ' here';
        }
        
        $html .= '<li class="sub_level_' . $entry['subDepth'] . $here . '">';
        $html .= '<a href="http://">' . $entry['title'];_        $html .= '</a>';
        
        $prev_subDepth = (int)$entry['subDepth'];
        $i++;
    }
    $html .= '</ul>';
    //$html .= '<pre>' . $sql . '</pre>

<p>’;
    return $html;
}
</pre>

Any idea what I could be doing wrong? I have made a custom status of ‘no_nav’ and have this structure tag

{exp:structure:nav_main exclude_status="no_nav"}
       
Jack McDade's avatar
Jack McDade
425 posts
about 16 years ago
Jack McDade's avatar Jack McDade

What was modified in this function?

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.