Skip to content

Instantly share code, notes, and snippets.

View ekka21's full-sized avatar

Ekkachai Danwanichakul ekka21

View GitHub Profile
@ekka21
ekka21 / gist:2992432
Created June 26, 2012 01:07
Wordpress: Remove menu items from WordPress admin bar
function wps_admin_bar() {
global $wp_admin_bar;
$wp_admin_bar->remove_menu('wp-logo');
$wp_admin_bar->remove_menu('about');
$wp_admin_bar->remove_menu('wporg');
$wp_admin_bar->remove_menu('documentation');
$wp_admin_bar->remove_menu('support-forums');
$wp_admin_bar->remove_menu('feedback');
$wp_admin_bar->remove_menu('view-site');
}
@ekka21
ekka21 / gist:2984925
Created June 24, 2012 20:59
Wordpress: corn job
//You probably know that WordPress can schedule events.
// In this recipe, I’ll show you how you create an event that will be executed once hourly, or daily, etc.
if (!wp_next_scheduled('my_task_hook')) {
wp_schedule_event( time(), 'hourly', 'my_task_hook' );
}
add_action( 'my_task_hook', 'my_task_function' );
function my_task_function() {
wp_mail('[email protected]', 'Automatic email', 'Hello, this is an automatically scheduled email from WordPress.');
@ekka21
ekka21 / gist:2975251
Created June 22, 2012 21:16
Wordpress: Post lists base on category
/* Posts List base on category*/
function imediapixel_postslist($category, $num, $orderby="date",$style="2col") {
global $post;
$category_id = get_cat_ID($category);
$cat_num = ($num) ? $num : 4;
$counter = 0;
$out = "";
query_posts('cat='.$category_id.'&showposts='.$cat_num.'&orderby='.$orderby);
@ekka21
ekka21 / gist:2975228
Created June 22, 2012 21:11
Wordpress: Page with child pages List
/* Page with child pages List */
function imediapixel_pagelist($page_name, $num, $orderby="menu_order",$style="2col") {
global $post;
$page_id = get_page_by_title($page_name);
$services_num = ($num) ? $num : 4;
$counter = 0;
$out = "";
@ekka21
ekka21 / gist:2975203
Created June 22, 2012 21:04
Wordpress: custom Breadcrumbs Navigation
/* Breadcrumbs Navigation */
function imediapixel_breadcrumbs() {
$delimiter = '»';
$name = __('Home','ecobiz'); //text for the 'Home' link
$currentBefore = '<span class="current">';
$currentAfter = '</span>';
if ( !is_home() && !is_front_page() || is_paged() ) {
@ekka21
ekka21 / gist:2975171
Created June 22, 2012 21:01
Wordpress: lastest post within category
//Function for showing lastest post within cat_id
function imediapixel_latestnews($blogcat,$num=4,$title="") {
global $post;
echo $title;
if(is_array($blogcat)) {
$blog_includes = implode(",",$blogcat);
} else {
$blog_includes = $blogcat;
@ekka21
ekka21 / gist:2966035
Created June 21, 2012 14:26
Wordpress: send email to subscriber when the post is published.
//Just paste the following code on your functions.php file
function email_members($post_ID) {
global $wpdb;
$usersarray = $wpdb->get_results("SELECT user_email FROM $wpdb->users;");
$users = implode(",", $usersarray);
mail($users, SUBJECT, CONTENT);
return $post_ID;
}
@ekka21
ekka21 / gist:2941837
Created June 16, 2012 16:23
jQuery: Form validation, call back function ajax
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js" type="text/javascript" charset="utf-8"></script>
$("#freeform").validate({
submitHandler: function() {
$.ajax({
url: "URL",
type: 'POST',
dataType: 'html',
data: ({
@ekka21
ekka21 / gist:2920356
Created June 12, 2012 21:52
Git: remove branch
git branch -D BRANCH_NAME
git push origin :BRANCH_NAME
@ekka21
ekka21 / gist:2919479
Created June 12, 2012 19:08
Wordpress: Add/Remove MineType
//Add mineType
add_filter('upload_mimes','add_custom_mime_types');
function add_custom_mime_types($mimes){
return array_merge($mimes,array (
'ac3' => 'audio/ac3',
'mpa' => 'audio/MPA',
'flv' => 'video/x-flv'
));
}