Skip to content

Instantly share code, notes, and snippets.

Avatar

Joost de Valk jdevalk

View GitHub Profile
@jdevalk
jdevalk / gist:1217431
Created Sep 14, 2011
new rel_canonical function
View gist:1217431
<?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 Oct 18, 2011
New index for Carly
View index.php
<?php
get_header();
query_posts('posts_per_page=4&cat=-46');
if (have_posts()) :
$first = true;
@jdevalk
jdevalk / wordstream-api-class.php
Created Oct 23, 2011
WordStream API interface class for WordPress
View wordstream-api-class.php
<?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 Nov 8, 2011
Function to move searches for non-post post-types / taxonomies to their respective archives.
View gist:1347575
<?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 Dec 20, 2011
Gravity Forms API
View gist:1500757
<?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 Jan 5, 2012
oembed function to use content_width appropriately
View gist:1565059
<?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 Feb 26, 2012
Turn a spiderable list of links into a dropdown + a go button with jQuery
View gist:1918689
<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 Mar 28, 2012
Link template
View links.php
@jdevalk
jdevalk / pinterest.php
Created Apr 16, 2012
Pinterest button shortcode
View pinterest.php
<?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'
View gist:2426489
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