Skip to content

Instantly share code, notes, and snippets.

@ivandoric
ivandoric / gist:11219129
Created April 23, 2014 15:08
sublime: Package Control doesn't work
Just add this to:
Preferences > Package Setteings > Settings - User
{
"auto_upgrade_last_run": 1331660912,
"repository_channels": [
"http://sublime.wbond.net/repositories.json"
]
}
@ivandoric
ivandoric / gist:11219200
Created April 23, 2014 15:10
jQuery: Vertical align elements
(function (jQuery) {
// VERTICALLY ALIGN FUNCTION
jQuery.fn.vAlign = function() {
return this.each(function(i){
var ah = jQuery(this).height();
var ph = jQuery(this).parent().height();
var mh = Math.ceil((ph-ah) / 2);
jQuery(this).css('padding-top', mh);
});
};
@ivandoric
ivandoric / gist:11219242
Created April 23, 2014 15:10
woocommerce: Control number of columns in Woocommerce catalog
<?php
//Just put it in functions.php
/* Number of columns in Woocommerce Loop */
global $woocommerce_loop;
$woocommerce_loop['columns'] = 2;
@ivandoric
ivandoric / gist:11219283
Created April 23, 2014 15:11
woocommerce: Add new currency to WooCommerce
<?php
// Just add it to functions.php
// Add currency / symbol
add_filter( 'woocommerce_currencies', 'add_rand_currency' );
add_filter( 'woocommerce_currency_symbol', 'add_rand_currency_symbol' );
function add_rand_currency( $currencies ) {
$currencies['HRK'] = __( 'Hrvatska kuna (Kn)', 'woothemes' );
@ivandoric
ivandoric / gist:11219318
Created April 23, 2014 15:12
php: str_ireplace multiple values
<?php
$find = array("vlaue1", "value2", "value3");
$replace = array("replacevalue1","replacevalue2","replacevalue3");
str_ireplace($find,$replace,$string);
?>
@ivandoric
ivandoric / gist:11219354
Created April 23, 2014 15:13
wordpress: Print the link of the featured image
<?php if ( has_post_thumbnail()) {
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full');
echo $large_image_url[0];
}
?>
@ivandoric
ivandoric / gist:11219384
Created April 23, 2014 15:14
wordpress: Add custom field to gallery popup Wordpress
<?php
/* For adding custom field to gallery popup */
function ime_autora_field($form_fields, $post) {
$form_fields["ime-autora"] = array(
"label" => __("Autor"),
"input" => "text",
"value" => get_post_meta($post->ID, "_ime-autora", true),
"helps" => __("Ime autora slike"),
@ivandoric
ivandoric / gist:11219463
Created April 23, 2014 15:15
wordpress: Multiple excerpt lenghts in wordpress
<?php
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
@ivandoric
ivandoric / gist:11220540
Created April 23, 2014 15:42
wordpress: Print featured image title insted of post title
/* Add this to functions.php */
<?php
function pj_featured_img_title() {
global $post;
$pj_thumbnail_id = get_post_thumbnail_id($post->ID);
$pj_thumbnail_image = get_posts(array('p' => $pj_thumbnail_id, 'post_type' => 'attachment', 'post_status' => 'any'));
if ($pj_thumbnail_image && isset($pj_thumbnail_image[0])) {
return $pj_thumbnail_image[0]->post_title;
}
@ivandoric
ivandoric / gist:11220615
Last active August 29, 2015 14:00
wordpress: Exclude certain categories
<?php /* Using this instead the_category */
function the_category_filter($thelist,$separator=' ') {
if(!defined('WP_ADMIN')) {
//list the category names to exclude
$exclude = array('Featured', 'Show');
$cats = explode($separator,$thelist);
$newlist = array();
foreach($cats as $cat) {
$catname = trim(strip_tags($cat));
if(!in_array($catname,$exclude))