Skip to content

Instantly share code, notes, and snippets.

View jdevalk's full-sized avatar
😀

Joost de Valk jdevalk

😀
View GitHub Profile
@jdevalk
jdevalk / gist:1217431
Created September 14, 2011 18:55
new rel_canonical function
<?php
// this would replace the rel_canonical function in wp-includes/link-template.php
/**
* Output rel=canonical
*
* @package WordPress
* @since 2.9.0
*/
@jdevalk
jdevalk / index.php
Created October 18, 2011 08:08
New index for Carly
<?php
get_header();
query_posts('posts_per_page=4&cat=-46');
if (have_posts()) :
$first = true;
@jdevalk
jdevalk / wordstream-api-class.php
Created October 23, 2011 19:39
WordStream API interface class for WordPress
<?php
/**
* Class containing all the functionality to get data from the WordStream API
*
* @link http://api.wordstream.com/doc/introduction
*
* @author Joost de Valk <joost@yoast.com>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
@jdevalk
jdevalk / gist:1347575
Created November 8, 2011 11:50
Function to move searches for non-post post-types / taxonomies to their respective archives.
<?php
function yoast_change_template( $template ) {
global $wp_query;
if ( !isset($wp_query->query_vars['taxonomy']) )
return $template;
$taxonomy = get_taxonomy( $wp_query->query_vars['taxonomy'] );
if ( is_search() && count( $taxonomy->object_type ) > 0 && !in_array( 'post', array_values($taxonomy->object_type) ) ) {
set_query_var('post_type', $taxonomy->object_type[0]);
$newtemplate = get_archive_template();
@jdevalk
jdevalk / gist:1500757
Created December 20, 2011 08:15
Gravity Forms API
<?php
// Add a search to filter the entires, the form_id is the form ID you see in the GET variable on the entries or edit page
$search = "";
$form_id = 4;
// Authentication (add a username if you want for more security)
if ( ! isset($_GET['key']) || $_GET['key'] != '<set an API Key>' )
die;
@jdevalk
jdevalk / gist:1565059
Created January 5, 2012 12:29
oembed function to use content_width appropriately
<?php
function yoast_oembed_dataparse( $html, $data, $url ) {
global $content_width;
preg_match( '/width="(\d+)"/', $html, $matches );
$width = $matches[1];
preg_match( '/height="(\d+)"/', $html, $matches );
$height = $matches[1];
$aspect_ratio = $width / $height;
@jdevalk
jdevalk / gist:1918689
Created February 26, 2012 19:58
Turn a spiderable list of links into a dropdown + a go button with jQuery
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
// Inspiration partly from: http://stackoverflow.com/questions/1897129
jQuery(document).ready(function($) {
$('ul.dropdown').each(function(){
var list = $(this);
var select = $(document.createElement('select'))
.attr('id',$(this).attr('id'))
@jdevalk
jdevalk / links.php
Created March 28, 2012 17:33
Link template
@jdevalk
jdevalk / pinterest.php
Created April 16, 2012 10:16
Pinterest button shortcode
<?php
// Usage [pin img="<url>" title="<title>"]
function yoast_pinterest_shortcode( $atts ) {
extract( shortcode_atts( array(
'url' => get_permalink(),
'img' => '',
'title' => get_the_title(),
'align' => 'alignright'
@jdevalk
jdevalk / gist:2426489
Created April 20, 2012 06:11
Search query
SELECT c.Content, c.Title, c.ID, c.CTID, c.RID, r.Sitename,
CASE WHEN c.Title LIKE '%conversion%' THEN 1 ELSE 0 END AS titlematch,
CASE WHEN c.Content LIKE '%conversion%' THEN 1 ELSE 0 END AS contentmatch,
MATCH (c.Title, c.Content) AGAINST ('conversion') AS relevance
FROM Chapters c LEFT JOIN Reviews r
ON c.RID = r.ID
WHERE MATCH(c.Title, c.Content) AGAINST ('conversion' IN BOOLEAN MODE)
HAVING relevance > 0
ORDER BY titlematch DESC, contentmatch DESC, relevance DESC
LIMIT 50