Skip to content

Instantly share code, notes, and snippets.

View solid-pixel's full-sized avatar

Alessandro Benassi solid-pixel

View GitHub Profile
@solid-pixel
solid-pixel / index.html
Created September 14, 2018 08:33
Custom radio button CSS only
<form action="#">
<p>
<input type="radio" id="test1" name="radio-group" checked>
<label for="test1">Apple</label>
</p>
<p>
<input type="radio" id="test2" name="radio-group">
<label for="test2">Peach</label>
</p>
<p>
@solid-pixel
solid-pixel / style.css
Created June 14, 2018 13:56
Limit text lenght to N lines
.giveMeEllipsis {
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: N; /* number of lines to show */
line-height: X; /* fallback */
max-height: X*N; /* fallback */
}
@solid-pixel
solid-pixel / scripts.js
Created June 5, 2018 10:01
jQuery ajax .load() - callback waits for images to load
$('#newsletter').load('content.html', function() {
var images = $('#newsletter img');
var nimages = images.length;
images.load(function() {
nimages--;
if(nimages == 0) {
// images loaded. now execute Callback:
alert('all images loaded!');
}
});
<div id="project-gallery">
<?php if( have_rows('gallery_repeater') ): ?>
<?php while ( have_rows('gallery_repeater') ) : the_row(); ?>
<?php
$projGalImgs = get_sub_field('gallery');
$size = 'full';
if( $projGalImgs ): ?>
@solid-pixel
solid-pixel / custom-javascript.js
Last active May 24, 2018 09:11
Hide element if tap/click outside of it
var menuIcon = $("#menu-icon-container");
var menu = $('#menu');
$(document).mouseup(function(e) {
if (!menuIcon.is(e.target) && menuIcon.has(e.target).length === 0 && menuIcon.hasClass('visible'))
{
menu.hide();
$(menuIcon).removeClass('visible');
}
@solid-pixel
solid-pixel / functions.php
Last active May 22, 2018 20:38
Automatically Set the First Post Image as a Featured Image in WordPress
function auto_featured_image() {
global $post;
if (!has_post_thumbnail($post->ID)) {
$attached_image = get_children( "post_parent=$post->ID&amp;post_type=attachment&amp;post_mime_type=image&amp;numberposts=1" );
if ($attached_image) {
foreach ($attached_image as $attachment_id => $attachment) {
set_post_thumbnail($post->ID, $attachment_id);
}
@solid-pixel
solid-pixel / footer.php
Last active May 22, 2018 10:03
Social Icons with ACF Repeater
@solid-pixel
solid-pixel / form.php
Last active May 15, 2018 22:13
CF7 File Upload Field with styling and Bootstrap 4 tooltip
<div class="file-upload-field">
<label class="form-label" for="form-attachment">
<h4 class="form-titles">Attachments <span class="form-optional">(optional)</span></h4>
<span class="font-italic form-file-spec">(.zip, .jpg or .png - max 20MB)</span>
<div class="solid-btn-tiny solid-btn-alt mt-1 file-btn"
data-toggle="tooltip"
@solid-pixel
solid-pixel / page.php
Created May 8, 2018 09:30
Bootstrap 4 Cards with Swiper Slider
<div class="container-fluid">
<div class="swiper-container">
<div class="swiper-wrapper">
<?php $the_query=new WP_Query( array( 'post_type'=> 'project' ) ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php $featured_img_url=get_the_post_thumbnail_url(get_the_ID(), 'full'); ?>
<div class="swiper-slide card">
@solid-pixel
solid-pixel / page.php
Last active January 25, 2021 16:03
Display WordPress Custom Posts with Bootstrap 4 Cards
<div class="container">
<div class="row justify-content-between">
<?php $the_query=new WP_Query( array( 'post_type'=> 'project' ) ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php $featured_img_url=get_the_post_thumbnail_url(get_the_ID(), 'full'); ?>
<div class="col-lg-4">
<div class="card mb-2">
<img class="card-img-top" src="<?php echo $featured_img_url ?>" alt="">
<div class="card-body">