Skip to content

Instantly share code, notes, and snippets.

Avatar

Luis Martins lmartins

View GitHub Profile
@lmartins
lmartins / upload-a-file.MD
Created Jan 2, 2019 — forked from ahmadawais/upload-a-file.MD
Upload a file using the WordPress REST API
View upload-a-file.MD

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 Jan 24, 2018
Make entire block clickable
View Block Click.js
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();
View check_for_external_links
View gist:068e1b90f7b64cf45091e532fa7a3f00
<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 Nov 16, 2017 — forked from carolineschnapp/related-products.liquid
Related Products — to add to product.liquid
View related-products.liquid
@lmartins
lmartins / gist:5cb70eb0dc1834020fa7b54c10cffec2
Created Apr 3, 2016 — forked from kyleaparker/gist:560a3847860bace1d680
[Shopify] Show multiple images per variant
View gist:5cb70eb0dc1834020fa7b54c10cffec2
<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 Jan 11, 2016 — forked from vividvilla/sale-flash.php
Display Discount/Offer percentage in WooCommerce
View sale-flash.php
<?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 Sep 23, 2015
Register taxonomies using Extended Taxos library https://github.com/johnbillion/extended-taxos
View taxonomies.php
/**
* ============================================================================
* TAXONOMIES
* ============================================================================
*/
$args = array(
'labels' => array(
'add_new_item' => __('Add New Category', 'wip')
)
@lmartins
lmartins / query.php
Created Aug 10, 2015
Query posts using the same taxonomy as the current post
View query.php
/**
* 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 Aug 29, 2015
Mixins for BEM style selectors.
View SassMeister-input.scss
// ----
// 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;
You can’t perform that action at this time.