Welcome Guest, Not a member yet? Register   Sign In
Navigation with Parent ids for pages
#1

[eluser]the_unforgiven[/eluser]
Hi All,

Help required on how to achieve the following:

I have a sidebar navigation, and i have setup the database to include a parent, so how can i code it so that it only shows in the navigation if the parent has children in like a jquery accordion type style.


So i have a list in my nav for example

Home
About
Services
Contact


But then the client adds a new page under services called test for example

the navigation would then look like

Home
About
Services (then on hover of services it expands to show the test page)
Test
Contact

So how would one achieve this ?

Here's all my code so far so maybe someone can help me.

Code:
Controller:

public function index($path = ''){
  
     $page = $this->wc_main->getPagePath($path);
    
  $this->front->set('page', $page);
  $this->front->set('navpages', $this->wc_pages->getAllPages());
  $this->front->set('title', ucfirst($page['title']));
  $this->front->set('metadesc', $page['meta_desc']);
  $this->front->set('metakeywords', $page['meta_keywords']);
  $this->front->buffer('content', 'site/index');
  $this->front->render();  
}

Code:
Model:

function getAllPages()
{
      $data = array();
   $this->db->limit(15);
   $this->db->where('show_on_home', '1');
    $this->db->order_by('order', 'asc');
      $Q = $this->db->get('wc_pages');
      if ($Q->num_rows() > 0){
         foreach ($Q->result_array() as $row){
          $data[] = $row;
         }
     }
     $Q->free_result();  
     return $data;
  }
    public function getParent()
{
  $data = array();
      $this->db->select('pid,title');
      
      $Q = $this->db->get('wc_pages');
      if ($Q->num_rows() > 0){
         foreach ($Q->result() as $row){
            if ($row->parent > 0){
                 $data[0][$row->parent]['children'][$row->pid] = $row->title;
             }
             else{
                 $data[0][$row->pid]['name'] = $row->title;
               }
         }
     }
     $Q->free_result();  
     return $data;

}

Code:
View:

<?php
foreach ($navpages as $page) { ?>
<ul>
<li><a href="&lt;?php echo site_url(); ?&gt;pages/&lt;?php echo $page['path']; ?&gt;" title="&lt;?php echo ucfirst(strtolower($page['title'])); ?&gt;">&lt;?php echo ucfirst(strtolower($page['title'])); ?&gt;</a></li>
</ul>
&lt;?php
}

?&gt;

Attached image show the database setup, can someone please help me acheive this?

Thanks in advance


Messages In This Thread
Navigation with Parent ids for pages - by El Forum - 06-03-2013, 06:49 AM
Navigation with Parent ids for pages - by El Forum - 06-05-2013, 08:40 AM
Navigation with Parent ids for pages - by El Forum - 06-05-2013, 05:24 PM
Navigation with Parent ids for pages - by El Forum - 06-06-2013, 06:05 AM
Navigation with Parent ids for pages - by El Forum - 06-06-2013, 04:40 PM
Navigation with Parent ids for pages - by El Forum - 06-07-2013, 01:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB