Skip to content

Instantly share code, notes, and snippets.

View odil-io's full-sized avatar
🪐

Odilio Witteveen odil-io

🪐
View GitHub Profile
@odil-io
odil-io / JS: DragTransform
Last active January 27, 2017 08:41 — forked from fta2012/DragTransform
Creeert een rechthoek waarvan je de hoeken kunt verslepen om een 3D effect transform te genereren voor een DOM element. Je kan in Chrome de gehele code plakken in de console. Vergeet niet de selector te veranderen!
var selector = 'img' // Replace this with the selector for the element you want to make transformable
jQuery.getScript('//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js', function() {
jQuery.getScript('//cdnjs.cloudflare.com/ajax/libs/numeric/1.2.6/numeric.min.js', function() {
(function() {
var $, applyTransform, getTransform, makeTransformable;
$ = jQuery;
@odil-io
odil-io / function.php
Created February 23, 2017 16:10
WooCommerce product count in category view
// WooCommerce category product count
add_filter( 'woocommerce_subcategory_count_html', 'jk_hide_category_count' );
function jk_hide_category_count() {
// No count
}
@odil-io
odil-io / functions.php
Created February 23, 2017 16:11
WooCommerce amount of columns in shop
// WooCommerce shop columns
add_filter('loop_shop_columns', 'loop_columns');
if (!function_exists('loop_columns')) {
function loop_columns() {
return 3; // 3 products per row
@odil-io
odil-io / file.php
Last active September 4, 2017 14:24
WordPress: comma seperated get_the_tags() list with "and"
<?php
// Get the tags
$tags = get_the_tags();
// Count total tags
$total_tags = count($tags);
// Set $i
$i=0;
@odil-io
odil-io / index.html
Created January 11, 2018 10:40
Google Maps: Direct link to Routing
https://www.google.com/maps/dir/Current+Location/Streetname%20housenumber+postalnumbers+postalletters+city
@odil-io
odil-io / readme.md
Last active January 23, 2018 13:01
Regex Youtube and Vimeo URL extraction
/**
 * Get Youtube video ID from URL
 *
 * @param string $url
 * @return mixed Youtube video ID or FALSE if not found
 */
function getYoutubeIdFromUrl($url) {
    $parts = parse_url($url);
    if(isset($parts['query'])){
@odil-io
odil-io / javascript.js
Last active February 28, 2018 10:06
JS: Vanilla Cross-Browser scroll position reporting
//https://stackoverflow.com/a/8028584
function getScrollPercent() {
var h = document.documentElement,
b = document.body,
st = 'scrollTop',
sh = 'scrollHeight';
return (h[st]||b[st]) / ((h[sh]||b[sh]) - h.clientHeight) * 100;
}
document.addEventListener('scroll', function(){
@odil-io
odil-io / file.php
Created May 17, 2018 11:45
WordPress: List Posts
<?php $args = array('post_type' => 'posttype', 'post__not_in' => array($post->ID), ); ?>
<?php $query = new wp_query( $args ); ?>
<?php if($query->have_posts()): ?>
<?php while( $query->have_posts() ) : ?>
<?php $query->the_post(); ?>
// All Post relative stuff here
<?php the_title(); ?>
<?php echo esc_url( get_post_permalink() ); ?>
@odil-io
odil-io / file.php
Last active June 29, 2018 13:46
WordPress: List Menu items, does NOT work with WP Nav Plus
<?php $locations = get_nav_menu_locations(); ?>
<?php $menu = wp_get_nav_menu_object( $locations['theme_location'] ); ?>
<?php $menu_items = wp_get_nav_menu_items( $menu->term_id ); ?>
<ul class="list-group list-group-flush">
<?php foreach ( (array) $menu_items as $key => $menu_item ): ?>
<li class="list-group-item list-group-item-action">
<a href="<?= $menu_item->url; ?>">
<?= $menu_item->title; ?>
@odil-io
odil-io / template-part.php
Last active August 2, 2022 07:42
PHP: Get Google Company Reviews
<?php
$api_key = 'YOUR_PLACES_API_KEY';
$place_id = 'PLACE_ID';
$file = file_get_contents( 'https://maps.googleapis.com/maps/api/place/details/json?placeid=' . $place_id . '&key=' . $api_key );
$json = json_decode( $file );
if ( is_object( $json ) ) :
foreach ( $json->result->reviews as $review ) :