Skip to content

Instantly share code, notes, and snippets.

@dcatkins40
dcatkins40 / Sticky Footer Javascript
Created March 6, 2013 16:20
Code to create a sticky footer with Javascript.
@dcatkins40
dcatkins40 / jQuery to Make iFrame Content Responsive
Created January 29, 2013 22:27
Without wrapping an iFrame in a second div container, this code will find all iFrames that you select and fit them to their containers. Great for dynamic content.
jQuery(window).load(function() {
var $allVideos = jQuery("iframe[src^='http://www.youtube.com']"); //Find all embedded iframes from YouTube and load them into an array
var $fluidElement = jQuery("Fluid_Width_Element").width();
$allVideos.each(function() {
jQuery(this).data('aspectRatio', this.height / this.width).removeAttr('height').removeAttr('width'); //Find the aspect ratio, store it, and remove the height and width attributes
var $aspectRatio = jQuery(this).data('aspectRatio');
jQuery(this).width($fluidElement).height($fluidElement * $aspectRatio); //Change the height and width of each iframe to fit the container
})
jQuery(window).resize(function() {
var $newWidth = $fluidElement; //When the window is resized, store the new width
@dcatkins40
dcatkins40 / RSS Reader to Sort by Category
Created January 25, 2013 16:49
A PHP RSS Reader that will sort through a RSS feed to only display posts tagged with a specific category.
<?php
$url = "$URL_of_feed";
$rss = simplexml_load_file($url);
$items = $rss->channel->item;
$count = 0;
if($rss) {
foreach($items as $item) {
if($count <= 1) {
$title = $item->title;
$description = $item->description;
@dcatkins40
dcatkins40 / Wordpress Dropdown Categories for Custom Taxonomies
Created January 24, 2013 18:52
Create a Wordpress dropdown using a function to change option values to custom taxonomies.
//Wordpress
/*functions.php
Input this function into the functions.php file to call when a dropdown is needed*/
function custom_taxonomy_dropdown( $taxonomy, $orderby = 'slug', $order = 'ASC', $limit = '-1', $name, $show_option_all = null, $show_option_none = null ) {
$args = array(
'orderby' => $orderby,
'order' => $order,
);
@dcatkins40
dcatkins40 / Use PHP to access JSON
Created January 22, 2013 16:23
Example of using an PHP to access JSON if jQuery fails.
<?php
$response = wp_remote_get( '$API_URL' );
if( is_wp_error( $response ) ) {
echo 'Something went wrong!';
} else {
echo 'Response:<pre>';
print_r( $response );
echo '</pre>';
}
@dcatkins40
dcatkins40 / Flexslider to Change Background Image
Last active December 11, 2015 10:29
Javascript code to use Flexslider to change a background image after each slide change.
$(document).ready(function() {
var imgArr = new Array (
<?php
$total = count(get_field('field'));
$count = 1;
while(the_repeater_field('field', $pagenumber)): ?>
'<?php the_sub_field('sub_field'); ?>'<?php if($count < $total){echo ',';} $count++; ?>
<?php endwhile; ?>
);
var n = 0;
@dcatkins40
dcatkins40 / Search Bar in Nav Menu
Created January 21, 2013 15:17
PHP code to place a search bar into the nav menu as a li. Pulls the search bar from search.php.
/*Wordpress
functions.php*/
add_filter('wp_nav_menu_items','add_search_box', 10, 2);
function add_search_box($items, $args) {
ob_start();
get_search_form();
$searchform = ob_get_contents();
ob_end_clean();