CodeIgniter Forums
Navigation with Parent ids for pages - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Navigation with Parent ids for pages (/thread-58325.html)



Navigation with Parent ids for pages - El Forum - 06-03-2013

[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


Navigation with Parent ids for pages - El Forum - 06-05-2013

[eluser]the_unforgiven[/eluser]
Help greatly appreciated on this please?


Navigation with Parent ids for pages - El Forum - 06-05-2013

[eluser]jairoh_[/eluser]
it's hard to tell with your codes and your database structure could be different from ours. just make some logic and algorithms for that.


Navigation with Parent ids for pages - El Forum - 06-06-2013

[eluser]the_unforgiven[/eluser]
Well that's not really helping me, i need help with the logic and everything to but in place, hence the forum post!
:0


Navigation with Parent ids for pages - El Forum - 06-06-2013

[eluser]jairoh_[/eluser]
can u post your db structure? Smile


Navigation with Parent ids for pages - El Forum - 06-07-2013

[eluser]the_unforgiven[/eluser]
Db structure is shown in the first post has an image