Skip to content

Instantly share code, notes, and snippets.

View JMWebDevelopment's full-sized avatar

Jacob Martella Web Development JMWebDevelopment

View GitHub Profile
/**
* Register the necessary fields to display post information correctly
*/
add_action( 'rest_api_init', 'theme_slug_register_rest_fields' );
function theme_slug_register_rest_fields() {
register_rest_field( 'post',
'comments',
array(
'get_callback' => 'theme_slug_get_comments',
.controller('SinglePost', ['$scope', '$http', '$stateParams', 'Comments', 'SortComments', function ($scope, $http, $stateParams, Comments, SortComments) {
$http.get(myLocalized.api_url + 'posts?slug=' + $stateParams.slug + '&_embed').success(function(res){
$scope.post.comments = SortComments.arrangeComments( $scope.post.comments );
$scope.numComments = $scope.post.comments.length;
});
}])
.service('SortComments', function () {
})
.service('SortComments', function () {
this.getCommentById = function ( commentID, comments_list ) {
}
this.getCommentDepth = function ( theComment, comments_list ) {
}
this.arrangeComments = function ( commentsList ) {
}
})
this.getCommentById = function ( commentID, comments_list ) {
for ( j = 0; j < comments_list.length; j++ ) {
if ( comments_list[j].comment_ID == commentID ) {
return comments_list[j];
}
}
}
this.getCommentDepth = function ( theComment, comments_list ) {
var depthLevel = 0;
while ( theComment.comment_parent > 0 ) {
theComment = this.getCommentById( theComment.comment_parent, comments_list );
depthLevel++;
}
return depthLevel;
}
this.arrangeComments = function ( commentsList ) {
var maxDepth = 0;
for ( i = commentsList.length - 1; i >= 0; i-- ) {
if ( commentsList[i].comment_approved != 1 ) {
commentsList.splice( i, 1 );
}
}
for ( i = 0; i
< commentsList.length; i += 1 ) {
commentsList[i].comment_children = [];
.directive('collection', function () {
return {
restrict: "E",
replace: true,
scope: {
collection: '='
},
template: "<ul><member ng-repeat='member in collection' member='member'></member></ul>"
}
})
.directive('member', function ($compile) {
return {
restrict: "E",
replace: true,
scope: {
member: '='
},
templateUrl: myLocalized.partials + 'comments.html',
link: function (scope, element, attrs) {
var collectionSt = '<collection collection="member.comment_children"></collection>';
<li id="comment-{{member.comment_ID}}" class="comment comment-{{member.comment_ID}} {{member.comment_parent ? 'child-comment post-parent-' + member.comment_parent : ''}}">
<header class="comment-header">
<h4 class="comment-name">{{member.comment_author}}</h4>
<h5 class="comment-date">{{ member.comment_date | date:"h:mm a" }} on {{ member.comment_date | date:"MMMM dd, yyyy" }}</h5>
</header>
<div class="comment-content" ng-bind-html="member.comment_content | unsafe"></div>
<footer class="reply">
<button id="reply-{{member.comment_ID}}" class="respond-to-comment button" onclick="replyToComment(this.id)">{{translations.reply}}</button>
</footer>
</li>