Skip to content

Instantly share code, notes, and snippets.

View Ahrengot's full-sized avatar
🤟

Jens Ahrengot Boddum Ahrengot

🤟
View GitHub Profile
@Ahrengot
Ahrengot / backbone-app.js
Created March 27, 2012 12:00
Backbone app from https://peepcode.com/products/backbone-ii used for best-practises reference
(function($) {
window.Album = Backbone.Model.extend({
isFirstTrack: function(index) {
return index == 0;
},
isLastTrack: function(index) {
return index >= this.get('tracks').length - 1;
@Ahrengot
Ahrengot / mobile-webapp.html
Created March 20, 2012 14:48
mobile-webapp
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=no;">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="apple-touch-icon-precomposed" sizes="114x114" href=img/icons/114x114.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="img/icons/72x72.png">
<link rel="apple-touch-icon-precomposed" sizes="57x57" href="img/icons/57x57.png">
<link rel="apple-touch-startup-image" href="img/icons/splash-screen.png" />
<body onload="setTimeout(function() { if(Modernizr.touch && window.pageYOffset <= 1) window.scrollTo(0, 1) }, 100);">
<!DOCTYPE html>
<!-- Helpful things to keep in your <head/>
// Brian Blakely, 360i
// http://twitter.com/brianblakely/
-->
<head>
<!-- Disable automatic DNS prefetching.
@Ahrengot
Ahrengot / wp-post-meta
Created March 12, 2012 15:38
Get post/page custom meta data
// Get multiple values with one DB query
$post_meta = get_post_custom();
$prefix = 'my_custom_field_';
$value_1 = $post_meta[$prefix . '1'][0];
$value_2 = $post_meta[$prefix . '2'][0];
$value_3 = $post_meta[$prefix . '3'][0];
// Get a single value
$value = get_post_meta(get_the_ID(), 'my_custom_field', true);
@Ahrengot
Ahrengot / index.html
Created March 6, 2012 10:29
basic HTML5 document
<!doctype html>
<html class="no-js" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml" lang="en-US">
<head>
<meta charset="utf-8">
<title>Untitled</title>
<style type="text/css">
body { background: white; color: #999; font-family: sans-serif; }
h1 { color: #333; }
</style>
@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 = '';
@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 / 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 / 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 / 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',