Last active
May 9, 2016 10:46
-
-
Save vishalbasnet23/e5a2aa4ff262fc7f5056d1dd1e728d46 to your computer and use it in GitHub Desktop.
Angular menu with custom routing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function angular_menu_builder() { | |
$locations = get_nav_menu_locations(); | |
$menu = wp_get_nav_menu_object($locations['primary']); | |
$menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'order' => 'DESC' ) ); | |
?> | |
<nav class="primary-nav-wrapper"> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-xs-12 col-sm-12 col-md-12"> | |
<div class="primary-menu"> | |
<ul> | |
<?php | |
$count = 0; | |
$submenu = false; | |
foreach( $menu_items as $item ): | |
if( $item->object == 'post' ) { | |
$menu_object_post_obj = get_post($item->object_id); | |
$item_frontend_slug = home_url().'#/posts/post/'.$menu_object_post_obj->post_name; | |
} elseif ($item->object == 'page' ) { | |
$menu_object_post_obj = get_post($item->object_id); | |
$item_frontend_slug = home_url().'#/pages/'.$menu_object_post_obj->post_name; | |
} elseif( $item->object == 'category' ) { | |
$menu_object_post_obj = get_category( $item->object_id ); | |
$item_frontend_slug = home_url().'#/posts/cat/'.$menu_object_post_obj->slug; | |
} | |
$link = $item_frontend_slug; | |
$title = $item->title; | |
if ( !$item->menu_item_parent ): | |
$parent_id = $item->ID; | |
?> | |
<li class="item"> | |
<a href="<?php echo $link; ?>" class="title"> | |
<?php echo $title; ?> | |
</a> | |
<?php endif; ?> | |
<?php if ( $parent_id == $item->menu_item_parent ): ?> | |
<?php if ( !$submenu ): $submenu = true; ?> | |
<ul class="sub-menu"> | |
<?php endif; ?> | |
<li class="item"> | |
<a href="<?php echo $link; ?>" class="title"><?php echo $title; ?></a> | |
</li> | |
<?php if ( $menu_items[ $count + 1 ]->menu_item_parent != $parent_id && $submenu ): ?> | |
</ul> | |
<?php $submenu = false; endif; ?> | |
<?php endif; ?> | |
<?php if ( $menu_items[ $count + 1 ]->menu_item_parent != $parent_id ): ?> | |
</li> | |
<?php | |
$submenu = false; endif; | |
$count++; endforeach; | |
?> | |
</ul> | |
</div> | |
</div> | |
</div> | |
</div> | |
</nav> | |
<?php } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular | |
.module('mainapp', [ | |
'ngAnimate', | |
'ngResource', | |
'ngRoute', | |
'ngSanitize' | |
]) | |
.config(function ($routeProvider) { | |
$routeProvider | |
.when('/', { | |
templateUrl: MainAppVar.templateDirectory+'/app/views/main.html', | |
controller: 'MainCtrl', | |
controllerAs: 'main' | |
}) | |
.when('/pages/:pageslug', { | |
templateUrl: MainAppVar.templateDirectory+'/app/views/page.html', | |
controller: 'PageCtrl', | |
controllerAs: 'page' | |
}) | |
.when('/pages/:pageslug/:childpage', { | |
templateUrl: MainAppVar.templateDirectory+'/app/views/childpage.html', | |
controller: 'ChildController', | |
controllerAs : 'childpage' | |
}) | |
.when('/pages/get-involved/member/new', { | |
templateUrl: MainAppVar.templateDirectory+'/app/views/get-involved.html', | |
controller: 'GetInvolvedCtrl', | |
controllerAs: 'getinvolved' | |
}) | |
.when('/posts/post/:slug', { | |
templateUrl: MainAppVar.templateDirectory+'/app/views/post.html', | |
controller: 'PostCtrl', | |
controllerAs: 'post' | |
}) | |
.when('/posts/cat/:cat', { | |
templateUrl: MainAppVar.templateDirectory+'/app/views/posts.html', | |
controller: 'PostsCtrl', | |
controllerAs: 'posts' | |
}) | |
.otherwise({ | |
redirectTo: '/' | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment