Skip to content

Instantly share code, notes, and snippets.

@yoren
yoren / functions.php
Created Mar 5, 2014
Exclude Subcategories in a Loop
View functions.php
<?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
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// 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 Aug 29, 2015
The anatomy of Quick Add Child
View admin.js
(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 Aug 29, 2015
Add icons to wp_list_categories
View functions.php
<?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 Oct 28, 2014
Change default style number in WordPress
View functions.php
<?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 Nov 5, 2014
Display a single WordPress post with AngularJS and JSON API
View content.html
<h1>{{post.title}}</h1>
{{post.content}}
@yoren
yoren / content.html
Last active Aug 29, 2015
Best Practice to sanitize HTML in AngularJS
View content.html
<h1>{{post.title}}</h1>
<div ng-bind-html="post.content"></div>
@yoren
yoren / content.html
Last active Aug 29, 2015
Bypass sanitization for values you know are safe
View content.html
<h1>{{post.title}}</h1>
<div ng-bind-html="post.content | toTrusted"></div>
@yoren
yoren / main.html
Last active Aug 29, 2015
Use AngularJS Custom Directives In A WordPress Theme
View main.html
<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 Aug 29, 2015
Minification Errors In My AngularJS WordPress Theme
View scripts-change-name.js
//Main controller
app.controller('Main', ['$scope', '$http', function(a, b) {
b.get('wp-json/posts/').success(function(res){
a.posts = res;
});
}]);