Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View yoren's full-sized avatar

Yoren Chang yoren

View GitHub Profile
@yoren
yoren / functions.php
Created March 5, 2014 14:27
Exclude Subcategories in a Loop
<?php
function wpse_filter_child_cats( $query ) {
if ( $query->is_category ) {
$queried_object = get_queried_object();
$child_cats = (array) get_term_children( $queried_object->term_id, 'category' );
if ( ! $query->is_admin )
//exclude the posts in child categories
@yoren
yoren / 0_reuse_code.js
Created May 31, 2014 15:09
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@yoren
yoren / admin.js
Last active August 29, 2015 14:03
The anatomy of Quick Add Child
(function ( $ ) {
"use strict";
var post_ID = $('#post_ID').val(),
parent_id = ( '' == $('#parent_id').val() ) ? 0 : $('#parent_id').val(),
addNew = $('.add-new-h2'),
html = '';
html += ' <a id="add_new_sibling" href="post-new.php?post_type=' + typenow + '&parent_id=' + parent_id + '" class="add-new-h2" target="_blank">' + quick_add_child_js_params.add_new_sibling + '</a>';
html += '<a id="add_new_child" href="post-new.php?post_type=' + typenow + '&parent_id=' + post_ID + '" class="add-new-h2" target="_blank">' + quick_add_child_js_params.add_new_child + '</a>';
@yoren
yoren / functions.php
Last active August 29, 2015 14:05
Add icons to wp_list_categories
<?php
function my_list_categories( $output, $args ) {
$pattern = '/(<a.*?>)/';
$replacement = '$1<i class="ico-my"></i> ';
return preg_replace( $pattern, $replacement, $output );
}
add_filter( 'wp_list_categories', 'my_list_categories', 10, 2 );
@yoren
yoren / functions.php
Created October 28, 2014 12:26
Change default style number in WordPress
<?php
function sp_wp_default_styles($styles)
{
//use our app version constant
$styles->default_version = SCHOOLPRESS_VERSION;
}
add_action("wp_default_styles", "sp_wp_default_styles");
@yoren
yoren / content.html
Created November 5, 2014 09:10
Display a single WordPress post with AngularJS and JSON API
<h1>{{post.title}}</h1>
{{post.content}}
@yoren
yoren / content.html
Last active August 29, 2015 14:09
Best Practice to sanitize HTML in AngularJS
<h1>{{post.title}}</h1>
<div ng-bind-html="post.content"></div>
@yoren
yoren / content.html
Last active August 29, 2015 14:09
Bypass sanitization for values you know are safe
<h1>{{post.title}}</h1>
<div ng-bind-html="post.content | toTrusted"></div>
@yoren
yoren / main.html
Last active August 29, 2015 14:12
Use AngularJS Custom Directives In A WordPress Theme
<search-form></search-form>
<ul>
<li ng-repeat="post in posts">
<a href="{{post.ID}}" ng-bind-html="post.title"></a>
<div ng-bind-html="post.content"></div>
</li>
</ul>
@yoren
yoren / scripts-change-name.js
Last active August 29, 2015 14:12
Minification Errors In My AngularJS WordPress Theme
//Main controller
app.controller('Main', ['$scope', '$http', function(a, b) {
b.get('wp-json/posts/').success(function(res){
a.posts = res;
});
}]);