Skip to content

Instantly share code, notes, and snippets.

View Ahrengot's full-sized avatar
🤟

Jens Ahrengot Boddum Ahrengot

🤟
View GitHub Profile
@Ahrengot
Ahrengot / Open Graph meta tags
Created October 21, 2011 19:32
Open Graph meta tags for web pages
<!-- Open Graph Protocol: http://developers.facebook.com/docs/opengraph/ -->
<!-- Required -->
<meta property="og:title" content="PAGE_TITLE"/>
<meta property="og:type" content="TYPE"/>
<meta property="og:url" content="FULL_URL"/>
<meta property="og:image" content="FULL_IMGAGE_URL_MIN_50x50PX"/>
<!-- Optional -->
<meta property="og:site_name" content="SITE_NAME"/>
@Ahrengot
Ahrengot / jq-plugin-boilerplate.js
Created December 23, 2011 15:12
jQuery Plugin boilerplate
(function($) {
$.fn.pluginName = function(options) {
var defaultOptions = {
option1: 'ahrengot',
option2: true,
option3: false
}
var options = $.extend(defaultOptions, options);
@Ahrengot
Ahrengot / inarray.js
Created January 7, 2012 18:17
Checks if value exists in array
function inArray(arr, val) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] == val) return true;
}
return false;
}
@Ahrengot
Ahrengot / javascript-toggle
Created January 23, 2012 09:52
Simple jQuery toggle class
var toggle = function(selector, parentSelector, switchMode, onSelect) {
var $items,
$containers;
this.init = function() {
$items = $(selector);
$containers = $items.parents(parentSelector);
$items.each(function() {
$(this).data('container', $(this).parents(parentSelector));
});
@Ahrengot
Ahrengot / parallax-scroll
Created January 25, 2012 13:50
Class for managing items with parallax scroll
function ParallaxScroll() {
this.$window = $(window);
this.items = new Array();
this.init = function() {
this.$window.scroll(doParallax);
}
var doParallax = function() {
// Check we have any items before we do any scolling
@Ahrengot
Ahrengot / query-meta-key-where-value
Created January 31, 2012 11:17
WordPress database query looking for specific keys and values
$default_query = array(
'posts_per_page' => -1,
'post_type' => 'kunstnere',
'order' => 'ASC',
'orderby' => 'meta_value',
'meta_key' => 'artist_meta_time_input',
'meta_query' => array(
array(
'key' => 'artist_meta_scene_select',
'value' => 'Scene 1',
@Ahrengot
Ahrengot / secondary-wp-loop
Created February 8, 2012 13:47
Secondary WordPress loop
// Used for secondary loops. To alter main loops use query_posts() instead.
// Documentation: http://codex.wordpress.org/Function_Reference/get_posts
global $post;
$post_backup = $post;
$myposts = get_posts( array('numberposts' => 5, 'offset'=> 1, 'category' => 1 ));
foreach( $myposts as $post ) {
setup_postdata($post);
the_content();
}
@Ahrengot
Ahrengot / alter-primary-wp-loop
Created February 8, 2012 13:48
Alter primary loop
// Used to alter main loop. For secondary loops use get_posts() or make a new instance of WP_Query()
<?php
query_posts( array ( 'post_type' => 'artists', 'posts_per_page' => -1, 'order' => 'ASC' ) );
if(have_posts()) : while (have_posts()) : the_post();
?>
<!-- stuff like the_title(); -->
<?php
endwhile;
endif;
@Ahrengot
Ahrengot / wp-rss-post-thumbnail
Created February 14, 2012 13:06
Include post thumbnail in WordPress RSS feed
function add_post_thumbnail_feeds($content) {
global $post;
if(has_post_thumbnail($post->ID)) {
$content = '<div>' . get_the_post_thumbnail($post->ID, 'medium') . '</div>' . $content;
}
return $content;
}
add_filter('the_excerpt_rss', 'add_post_thumbnail_feeds');
add_filter('the_content_feed', 'add_post_thumbnail_feeds');
@Ahrengot
Ahrengot / get-video-id.php
Created March 5, 2012 09:50
Parses a URL and returns the correct video ID based on service.
/**
* Parses a URL and returns the correct video ID based on service.
*
* @param string $url the URL to parse
* @param string $service 'youtube', 'vimeo' etc.
*
* @return string
*/
function get_video_id($url, $service = 'youtube') {
$match = '';