[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="<?php echo site_url(); ?>pages/<?php echo $page['path']; ?>" title="<?php echo ucfirst(strtolower($page['title'])); ?>"><?php echo ucfirst(strtolower($page['title'])); ?></a></li>
</ul>
<?php
}
?>
Attached image show the database setup, can someone please help me acheive this?
Thanks in advance