Skip to content

Instantly share code, notes, and snippets.

View lmartins's full-sized avatar

Luis Martins lmartins

  • Goodwin Media, Multiweb
  • Portugal
View GitHub Profile
@lmartins
lmartins / upload-a-file.MD
Created January 2, 2019 14:35 — forked from ahmadawais/upload-a-file.MD
Upload a file using the WordPress REST API

Upload files

Using the REST API to upload a file to WordPress is quite simple. All you need is to send the file in a POST-Request to the wp/v2/media route.

There are two ways of sending a file. The first method simply sends the file in the body of the request. The following PHP script shows the basic principle:

@lmartins
lmartins / Block Click.js
Created January 24, 2018 16:43
Make entire block clickable
delegate(document.body, '.js-clickBlock', 'click', function(e) {
// If already a link bailout
if (e.target.tagName == "A" || e.target.tagName == "BUTTON") {
return;
}
let link = e.delegateTarget.querySelector('a');
if (link && link.href) {
e.preventDefault();
<div>
<label for="sort-by">Sort by</label>
<select id="sort-by">
<option value="manual">Featured</option>
<option value="price-ascending">Price: Low to High</option>
<option value="price-descending">Price: High to Low</option>
<option value="title-ascending">A-Z</option>
<option value="title-descending">Z-A</option>
<option value="created-ascending">Oldest to Newest</option>
<option value="created-descending">Newest to Oldest</option>
@lmartins
lmartins / related-products.liquid
Created November 16, 2017 11:29 — forked from carolineschnapp/related-products.liquid
Related Products — to add to product.liquid
@lmartins
lmartins / gist:5cb70eb0dc1834020fa7b54c10cffec2
Created April 3, 2016 10:08 — forked from kyleaparker/gist:560a3847860bace1d680
[Shopify] Show multiple images per variant
<script>
jQuery(document).ready(function($){
var images = [];
{% for image in product.images %}
images.push({url: "{{ image | product_img_url: 'medium' }}", alt: "{{ image.alt }}"});
{% endfor %}
var thumbnails = $(".thumbs");
@lmartins
lmartins / sale-flash.php
Created January 11, 2016 21:07 — forked from vividvilla/sale-flash.php
Display Discount/Offer percentage in WooCommerce
<?php
/**
* Product loop sale flash
*
* @author Vivek R @ WPSTuffs.com
* @package WooCommerce/Templates
* @version 1.6.4
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
@lmartins
lmartins / taxonomies.php
Created September 23, 2015 18:01
Register taxonomies using Extended Taxos library https://github.com/johnbillion/extended-taxos
/**
* ============================================================================
* TAXONOMIES
* ============================================================================
*/
$args = array(
'labels' => array(
'add_new_item' => __('Add New Category', 'wip')
)
@lmartins
lmartins / query.php
Created August 10, 2015 09:39
Query posts using the same taxonomy as the current post
/**
* QUERY DESIGNS DO VERTICAL
* http://wordpress.stackexchange.com/questions/139571/display-posts-with-same-taxonomy-term
*/
$vertical_terms = wp_get_object_terms( $post->ID, 'vertical_cat' );
if( $vertical_terms ){
// going to hold our tax_query params
@lmartins
lmartins / SassMeister-input.scss
Last active August 29, 2015 14:25
Mixins for BEM style selectors.
// ----
// libsass (v3.2.5)
// ----
// BEM Mixins for SASS
// http://www.sitepoint.com/structuring-css-class-selectors-with-sass/
@mixin new($block) {
@at-root .#{$block} {
@content;