Skip to content

Instantly share code, notes, and snippets.

View DevelopKim's full-sized avatar

Develop.Kim DevelopKim

View GitHub Profile
/**
* Load different template for sub category
*/
function sub_category_template() {
// Get the category id from global query variables
$cat = get_query_var('cat');
if(!empty($cat)) {
function new_subcategory_hierarchy() {
$category = get_queried_object();
$parent_id = $category->category_parent;
$templates = array();
if ( $parent_id == 0 ) {
// Use default values from get_category_template()
$templates[] = "category-{$category->slug}.php";
function add_slug_class_to_menu_item($output){
$ps = get_option('permalink_structure');
if(!empty($ps)){
$idstr = preg_match_all('/<li id="menu-item-(\d+)/', $output, $matches);
foreach($matches[1] as $mid){
$id = get_post_meta($mid, '_menu_item_object_id', true);
$slug = basename(get_permalink($id));
$output = preg_replace('/menu-item-'.$mid.'">/', 'menu-item-'.$mid.' menu-item-'.$slug.'">', $output, 1);
}
}
<?php
function add_menu_icons_styles(){
?>
 
<style>
#adminmenu .menu-icon-events div.wp-menu-image:before {
content: '\f145';
}
</style>
(function(console){
console.save = function(data, filename){
if(!data) {
console.error('Console.save: No data')
return;
}
if(!filename) filename = 'console.json'
function detect_ie()
{
if (isset($_SERVER['HTTP_USER_AGENT']) &&
(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
return true;
else
return false;
}
//to safely serialize
$safe_string_to_store = base64_encode(serialize($multidimensional_array));
//to unserialize...
$array_restored_from_db = unserialize(base64_decode($encoded_serialized_string));
@DevelopKim
DevelopKim / dateformatting
Created August 28, 2013 08:54
javascript date formatting
var today = new Date();
var delimeter = '/';
var formatDate = today.getFullYear() + delimeter +
('0' + (today.getMonth() + 1)).slice(-2) + delimeter +
('0' + today.getDate()).slice(-2);
//ex . Wed Aug 28 2013 17:50:28 GMT+0900 (KST) -> "2013/08/28"
@DevelopKim
DevelopKim / gist:2167475
Created March 23, 2012 06:01
PHP debug logging file and browser
<?
//logging file
function debug_log($message = '<==========DEBUG LOG========>'){
//directory log file
$dir = $_SERVER['DOCUMENT_ROOT'].'/logs';
//save Output Buffer
ob_start();
print_r($message);
$message = ob_get_clean();
if(!file_exists($dir)){