Skip to content

Instantly share code, notes, and snippets.

View n8finch's full-sized avatar

Nate Finch n8finch

View GitHub Profile
@n8finch
n8finch / filter-nav-menu-items-genesis-angular-gulp.php
Created September 19, 2016 03:45
filter-nav-menu-items-genesis-angular-gulp
add_filter( 'wp_setup_nav_menu_item', __NAMESPACE__ . '\filter_nav_menu_items', 1 );
function filter_nav_menu_items( $menu ) {
$post_type = ( $menu->object ); //gets post type
//if post type is a page, then create a new URL
if ( $post_type === 'page' ) {
$menu_url = $menu->url;
$new_url = '/pages' . str_replace( 'https://n8finch.dev/', '/', $menu_url );
$menu->url = $new_url;
}
@n8finch
n8finch / page-view-genesis-angular-gulp.html
Created September 19, 2016 03:44
page-view-genesis-angular-gulp.html
<article class="single-post post type-post status-publish format-standard has-post-thumbnail entry"
ng-controller="pageView">
<header class="entry-header">
<h2 class="entry-title">{{post.title.rendered}}</h2>
</header>
<img class="attachment-post-image size-post-image wp-post-image" ng-src="{{post.featured_image_src}}"/>
<div class="entry-content">
<p ng-bind-html="post.content.rendered | to_trusted"></p>
</div>
<footer class="entry-footer">
@n8finch
n8finch / pageView-controller-genesis-angular-gulp.js
Created September 19, 2016 03:44
pageView-controller-genesis-angular-gulp.js
.controller('pageView', ['$scope', '$http', '$stateParams', function ($scope, $http, $stateParams) {
console.log('pageView running');
$http({
url: 'https://n8finch.dev/wp-json/wp/v2/pages?filter[name]=' + $stateParams.slug,
cache: true
}).success(function (res) {
$scope.post = res[0];
});
}])
@n8finch
n8finch / app-index-genesis-angular-gulp.html
Created September 19, 2016 03:18
app-index-genesis-angular-gulp.html
<div ng-controller="Posts" ng-repeat="post in posts">
<article class="single-post post type-post status-publish format-standard has-post-thumbnail entry">
<header class="entry-header">
<h2 class="entry-title"><a href="/posts/{{post.slug}}/">{{post.title.rendered}}</a></h2>
<p class="entry-meta">Posted by {{post.author_name}} on {{post.date | date:'longDate'}}</p>
</header>
<img class="attachment-post-image size-post-image wp-post-image" ng-src="{{post.featured_image_src}}"/>
<div class="entry-content">
<p ng-bind-html="post.excerpt.rendered | to_trusted"></p>
<p><a href="/posts/{{post.slug}}/">Read more...</a></p>
@n8finch
n8finch / single-html-template-genesis-angular-gulp.html
Created September 19, 2016 03:11
single-html-template-genesis-angular-gulp.html
<article class="single-post post type-post status-publish format-standard has-post-thumbnail entry"
ng-controller="singleView">
<header class="entry-header">
<h2 class="entry-title">{{post.title.rendered}}</h2>
<p class="entry-meta">Posted by {{post.author_name}} on {{post.date | date:'longDate'}}</p>
</header>
<img class="attachment-post-image size-post-image wp-post-image" ng-src="{{post.featured_image_src}}"/>
<div class="entry-content">
<p ng-bind-html="post.content.rendered | to_trusted"></p>
</div>
@n8finch
n8finch / singleView-controller-genesis-angular-gulp.js
Created September 19, 2016 03:10
singleView-controller-genesis-angular-gulp.js
.controller('singleView', ['$scope', '$http', '$stateParams', function ($scope, $http, $stateParams) {
console.log('singleview running');
$http({
url: 'https://n8finch.dev/wp-json/wp/v2/posts?filter[name]=' + $stateParams.slug,
cache: true
}).success(function (res) {
$scope.post = res[0];
});
}]);
@n8finch
n8finch / routes-for-genesis-angular-gulp-app.js
Last active September 18, 2016 10:36
routes-for-genesis-angular-gulp-app
//ROUTES
.config([ '$stateProvider', '$urlRouterProvider', '$locationProvider', function ($stateProvider, $urlRouterProvider, $locationProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider
.state('posts', {
url: '/',
controller: 'Posts',
templateUrl: ajaxInfo.template_directory + 'assets/templates/app-index.html'
})
.state('single', {
@n8finch
n8finch / angular-basic-module.js
Created September 18, 2016 10:31
angular.module('myApp', ['ngResource', 'ui.router'])
angular.module('myApp', ['ngResource', 'ui.router'])
//CONTROLLERS
.controller('Posts', ['$scope', '$http', function ($scope, $http) {
$http({
url: 'https://n8finch.dev/wp-json/wp/v2/posts',
cache: true
}).success(function (res) {
$scope.posts = res;
});
genesis-angular-gulp
|__assets
|__js
|__app.js (our Angular app)
|__templates
|__app-index.html (our main list of posts from Part 2)
|__page.html (our page view for Pages)
|__single.html (our single view for individual Posts)
@n8finch
n8finch / add-new-custom-routes.php
Created August 29, 2016 15:51
add-new-custom-routes.php
//*Add a controller in the Angular view to work with
add_action('genesis_loop', __NAMESPACE__ . '\do_ng_view_content');
function do_ng_view_content() {
$output = '<div ng-controller="example">'.
'<div class="posts-list" ng-repeat="post in posts">'.
'<div class="single-post">'.
'<h2>{{post.title.rendered}}</h2>'.
'<p>Posted by {{post.author_name}} on {{post.date | date:\'longDate\'}}</p>'.
'<img ng-src="{{post.featured_image_src}}"/>'.
'<a href="{{post.slug}}">Read more...</a>'.