Skip to content

Instantly share code, notes, and snippets.

@alwayscoding
alwayscoding / gist:5243906
Created March 26, 2013 08:31
WORDPRESS: LIMIT POSTS NUMBER IN ARCHIVE PAGE
/**
* set the limit number of posts in archive page
* @return none
*/
function limit_posts_per_archive_page() {
if ( is_date() )
$limit = 10;
elseif ( is_search() )
$limit = 10;
else
@alwayscoding
alwayscoding / gist:5222043
Created March 22, 2013 15:15
WORDPRESS: CREATE CUSTOM POST TYPE
/**
* ADD HELLOPEOPLE POST TYPE
*/
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type('celebrities', array( 'label' => 'Celebrities','description' => 'Display images in three columns','public' => true,'show_ui' => true,'show_in_menu' => true,'capability_type' => 'post','hierarchical' => true,'rewrite' => array('slug' => ''),'query_var' => true,'has_archive' => true,'exclude_from_search' => false,'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes',),'taxonomies' => array('celebrities',),'labels' => array (
'name' => 'Celebrities',
'singular_name' => 'celebrity',
'menu_name' => 'Celebrities',
@alwayscoding
alwayscoding / gist:5182396
Created March 17, 2013 16:48
WORDPRESS: GET TIME SINCE PUBLISHED
/**
* GET TIME SINCE PUBLISHED
*/
function get_time_since_posted() {
$time_since_posted = human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) . ' 전에';
return $time_since_posted;
@alwayscoding
alwayscoding / gist:5155941
Created March 13, 2013 20:41
WORDPRESS: ADD POST/PAGE ID COLUMNS
add_filter('manage_posts_columns', 'posts_columns_id', 5);
add_action('manage_posts_custom_column', 'posts_custom_id_columns', 5, 2);
add_filter('manage_pages_columns', 'posts_columns_id', 5);
add_action('manage_pages_custom_column', 'posts_custom_id_columns', 5, 2);
function posts_columns_id($defaults){
$defaults['wps_post_id'] = __('ID');
return $defaults;
}
function posts_custom_id_columns($column_name, $id){
if($column_name === 'wps_post_id'){
@alwayscoding
alwayscoding / gist:5151019
Last active December 14, 2015 21:28
PHP: THE LAST MULTIBYTE CHAR FROM A STRING
mb_strrchr($string, 'CHAR')
@alwayscoding
alwayscoding / gist:5150862
Created March 13, 2013 10:23
PHP: REMOVE THE LAST MULTIBYTES CHAR
$string = mb_substr($string,0,-1);
@alwayscoding
alwayscoding / gist:5150469
Last active December 14, 2015 21:19
STYLE: WRAP FLOAT ELEMENT
#box {
position: relative;
border: 1px solid #E0E0E0;
}
#box:before, #box:after {
display: block;
content: "";
clear: both;
}
@alwayscoding
alwayscoding / gist:5142352
Last active March 12, 2018 16:16
WORDPRESS:GET ALL TAGS FROM A CATEGORY
//FUNCTION FILE
function get_category_tags($args) {
global $wpdb;
$tags = $wpdb->get_results
("
SELECT DISTINCT terms2.term_id as tag_id, terms2.name as tag_name, null as tag_link
FROM
wp_posts as p1
LEFT JOIN wp_term_relationships as r1 ON p1.ID = r1.object_ID
LEFT JOIN wp_term_taxonomy as t1 ON r1.term_taxonomy_id = t1.term_taxonomy_id
@alwayscoding
alwayscoding / gist:5141622
Created March 12, 2013 09:47 — forked from sjwilliams/gist:3903157
SHORTCUT: SUBLIMETEXT2

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘KB toggle side bar
⌘⇧P command prompt
⌃ ` python console
⌘⇧N new window (useful for new project)
@alwayscoding
alwayscoding / gist:5135112
Created March 11, 2013 15:38
WORDPRESS: TAGS IN A CATEGORY
query_posts('category_name=category-slug');
if (have_posts()) :
while (have_posts()) : the_post();
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
$all_tags_arr[] = $tag->name; //USING JUST $tag MAKING $all_tags_arr A MULTI-DIMENSIONAL ARRAY, WHICH DOES WORK WITH array_unique
}