Skip to content

Instantly share code, notes, and snippets.

View ekka21's full-sized avatar

Ekkachai Danwanichakul ekka21

View GitHub Profile
@ekka21
ekka21 / gist:2597615
Created May 4, 2012 20:45 — forked from luetkemj/wp-query-ref.php
Wordpress: wp_query
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query
* Source: http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/query.php
*/
$args = array(
@ekka21
ekka21 / gist:2793994
Created May 26, 2012 13:40
Wordpress: Custom Queries
//*** Article from http://wp.tutsplus.com/tutorials/creative-coding/writing-custom-queries-in-wordpress/
//The query function needs a string containing the custom query. The returnng value is an integer corresponding //to the number of rows affected/selected, and false when there is an error.
$query = "SELECT COUNT(apple) FROM fruits";
$wpdb->query($query);
//This function gets multiple rows when executing a query. By default the result of the function is an array.
$query = "
SELECT *
@ekka21
ekka21 / gist:2794063
Created May 26, 2012 14:01
Wordpress: virtual editor
<?php
//Set the Visual Editor Width Relative to Your Themes Content Width
add_action( 'after_setup_theme', 'wptuts_theme_setup' );
function wptuts_theme_setup() {
set_user_setting( 'dfw_width', 1000 );//In this example the full width will be 1000 pixels.
}
add_action( 'after_setup_theme', 'wptuts_theme_setup' );
function wptuts_theme_setup() {
@ekka21
ekka21 / select value
Created June 4, 2012 14:33
jQuery: Get a select value
$('#digital_element').change(function() {
alert($(this).val());
});
@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'
));
}
@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: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: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: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:2975203
Created June 22, 2012 21:04
Wordpress: custom Breadcrumbs Navigation
/* Breadcrumbs Navigation */
function imediapixel_breadcrumbs() {
$delimiter = '&raquo;';
$name = __('Home','ecobiz'); //text for the 'Home' link
$currentBefore = '<span class="current">';
$currentAfter = '</span>';
if ( !is_home() && !is_front_page() || is_paged() ) {