Skip to content

Instantly share code, notes, and snippets.

@1-800-jono
1-800-jono / add_extra_post_type_to_loop.php
Last active March 26, 2018 16:58
WordPress: Add extra post types to main WP post loop. Add this code to functions.php file.
add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
if ( is_home() && $query->is_main_query() ) {
$query->set( 'post_type', array( 'post', 'custom_post_name' ) );
$query->set( 'order', 'ASC');
$query->set( 'posts_per_page', 3);
}
@1-800-jono
1-800-jono / archive-custom-post-type.php
Last active March 9, 2018 15:25
WordPress - Simple Custom Post Type Archive (listing) with Term (Category) Filter. No AJAX. Before Adding all this you need to create the Custom Post Type and Custom Taxonomy using functions.php code or CPT UI plugin. Whichever floats your plastic kayak.
<?php
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<div class="cpt__filter wrapper">
<?php
$custom_type = 'cpt_slug';
@1-800-jono
1-800-jono / smooth-scrolling-jquery.js
Created February 21, 2018 14:30
Smooth scrolling using anchor tags - jQuery
///////////////////////////////
//Smooooth scrolling
////////////////
var root = jQuery('html, body');
jQuery('.menu li a').click(function() {
var href = jQuery.attr(this, 'href');
var offset = jQuery(href).offset();
var scrollto = offset.top - 100; // 100 here is the offsetb needed bacause of top sticky nav
root.animate({
@1-800-jono
1-800-jono / dnsmasq_setup_osx.md
Created January 29, 2018 18:17 — forked from eloypnd/dnsmasq_setup_osx.md
wildcard DNS record on OS X in localhost development with dnsmasq

wildcard DNS in localhost development

$ brew install dnsmasq
   ...
$ cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf
  • edit /usr/local/etc/dnsmasq.conf
address=/local/127.0.0.1
@1-800-jono
1-800-jono / addComma.js
Created October 23, 2017 16:48
Adds a comma to numbers
var number = 12345.543;
number.toLocaleString('en')
@1-800-jono
1-800-jono / carDepreciationRate.js
Created October 22, 2017 15:29
JS function to calculate car depreciation rate based on 14% rate
function calculateDepreciation(startPrice, years) {
for (i = 1; i <= years; i++) {
const result = startPrice * Math.pow((1 - 14/100), i);
console.log(Math.round(result).toLocaleString('en'))
}
}
calculateDepreciation(29000, 5)
@1-800-jono
1-800-jono / fluid-property.js
Last active July 5, 2018 18:54
JavaScript Fluid Property function for CSS - best with Styled-components. Example: `fp('font-size', 25, 40)`
//The fp() “Fluid Property” function
export function fp(property, min, max, start = 320, end = 1400, clip = true, clipAtStart = true, clipAtEnd = true) {
const multiplier = (max - min) / (end - start) * 100;
const adder = (min * end - max * start) / (end - start);
const formula = `calc((${multiplier}vw) + (${adder}px))`;
return`
@media (max-width: ${start}px) {
${property}: ${min}px;
}
@1-800-jono
1-800-jono / object-fit.css
Created October 4, 2017 16:02
Crop image and center with CSS - similar to background: cover
img {
object-fit: cover;
}
@1-800-jono
1-800-jono / undo_git_pull
Created October 2, 2017 17:47
git reset --keep HEAD@{1}
git reset --keep HEAD@{1}
@1-800-jono
1-800-jono / fluid-property
Last active February 6, 2018 20:45
Creates fluid/responsive properties using JS
//The fp() “Fluid Property” SCSS mixin
export function fp(property, min, max, start = 320, end = 1400, clip = true, clipAtStart = true, clipAtEnd = true) {
const multiplier = (max - min) / (end - start) * 100;
const adder = (min * end - max * start) / (end - start);
const formula = `calc((${multiplier}vw) + (${adder}px))`;
return`
@media (max-width: ${start}px) {
${property}: ${min}px;
}