Skip to content

Instantly share code, notes, and snippets.

View ashleycam3ron's full-sized avatar

Ashley N Cameron ashleycam3ron

View GitHub Profile
@ashleycam3ron
ashleycam3ron / get attachment image
Created September 6, 2012 20:11
Wordpress :: get attachment image
<?php
$attachment_id = $page->ID;
$current = get_the_ID();
$attachment = get_post( $attachment_id );
$args = array(
'post_type' => 'attachment',
'post_parent' => $current,
'post_mime_type' => 'image',
'post_status' => null,
'numberposts' => -1,
@ashleycam3ron
ashleycam3ron / index.html
Created November 11, 2017 02:07
Slider Parallax Effect
<!--
Inspired by Jardson Almeida
https://dribbble.com/shots/2518516-Nike-Promotion-Ads-Parallax-Effect
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Nike Parallax Cards</title>
@ashleycam3ron
ashleycam3ron / wp_custom_loop_with_pagination
Created January 13, 2018 17:00
WordPress custom loop with pagination
<?php
if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} elseif ( get_query_var('page') ) { // 'page' is used instead of 'paged' on Static Front Page
$paged = get_query_var('page');
} else {
$paged = 1;
}
$custom_query_args = array(
@ashleycam3ron
ashleycam3ron / check-nth-post.php
Created January 13, 2018 17:01 — forked from bryceadams/check-nth-post.php
check every nth post wordpress
<?php
// $the_query would just be a standard WP_Query
if ( $the_query->have_posts() ) :
$counter = 1;
while ( $the_query->have_posts() ) : $the_query->the_post();
if ( $counter % columns == 1 ) {
// do something at the start of your 'row'
@ashleycam3ron
ashleycam3ron / functions.php
Created February 2, 2018 19:39
Register and Enqueue Font Awesome in WordPress
<?php
add_action('wp_enqueue_scripts', 'enqueue');
function enqueue(){
//Font Awesome
wp_register_script('font-awesome', '//use.fontawesome.com/releases/v5.0.6/js/all.js');
//enqueue scripts
wp_enqueue_script(array('jquery','font-awesome'));
@ashleycam3ron
ashleycam3ron / functions.php
Created February 18, 2018 16:24
Add WordPress Jetpack Publicize to Custom Post Types
$args = array(
'supports' => array( 'title', 'editor', 'thumbnail', 'publicize')
)
<?php /* Loop through Promotion and Display Vendors as heading and promo posts within */
$post_type = 'promotion';
// Get all the taxonomies for this post type
$object = 'post';
$output = 'objects';
$taxonomies = get_object_taxonomies( $object, $output );
$exclude = array( 'post_tag','post_format','category' );
foreach( $taxonomies as $taxonomy ) :
@ashleycam3ron
ashleycam3ron / gist:983db3d607abd9a1692020391a1d1a73
Last active July 4, 2018 15:19
Loop through CPT and Display Taxonomy Terms as heading if posts exist and CPT posts within
<?php
$tax_args = array(
'orderby' => 'title',
'order' => 'ASC',
'hide_empty' => true,
);
$terms = get_terms('vendors', $tax_args);
foreach($terms as $term){
@ashleycam3ron
ashleycam3ron / add_title_and_alt_to_post_thumbnail.php
Created February 17, 2020 22:13
Add Title and Alt Attribute to WordPress Image the_post_thumbnail
<?php /* Add Title and Alt Attribute to WordPress Image the_post_thumbnail */
function ac_add_img_title( $attr, $attachment = null ) {
$img_title = trim( strip_tags( $attachment->post_title ) );
// or get the title instead of image title $attr['title'] = the_title_attribute( 'echo=0' );
$attr['title'] = $img_title;
$attr['alt'] = $img_title;
return $attr;
}
@ashleycam3ron
ashleycam3ron / Excel VBA Script
Last active April 5, 2021 15:56
Excel vlookup to return multiple values as comma separated list in one cell
Option Explicit
Function LookupCSVResults(lookupValue As Variant, lookupRange As Range, resultsRange As Range) As String
Dim s As String 'Results placeholder
Dim sTmp As String 'Cell value placeholder
Dim r As Long 'Row
Dim c As Long 'Column
Const strDelimiter = "|||" 'Makes InStr more robust
s = strDelimiter