Skip to content

Instantly share code, notes, and snippets.

View coreyweb's full-sized avatar

corey brown coreyweb

View GitHub Profile
@coreyweb
coreyweb / gist:2194903
Created March 25, 2012 14:04
WordPress: Remove [...] from the_excerpt
<?php
// put this code in the theme's functions.php file
function trim_excerpt($text) {
return rtrim($text,'[...]');
}
add_filter('get_the_excerpt', 'trim_excerpt')
?>
@coreyweb
coreyweb / gist:2195035
Created March 25, 2012 14:07
WordPress: Exclude category name from displaying on site
<?php
// place this in your theme's function.php file
function the_category_filter($thelist,$separator=' ') {
if(!defined('WP_ADMIN')) {
//list the category names to exclude
$exclude = array('Some Category','Another Category','Blah Blah Blah');
@coreyweb
coreyweb / wp-pagination-css
Created April 18, 2012 00:24
WordPress Pagination Replacement
// Some custom styling examples
/* category pagination */
.pagination {
margin: 0 0 10px 0; padding: 10px 0; border-top: 1px solid #ccc;
}
.page-numbers {
font-family:proxima-nova,Arial, Helvetica, sans-serif;
font-weight: normal;
font-size: 15px;
}
@coreyweb
coreyweb / gist:2424348
Created April 19, 2012 21:33
Amazon Product Advertising API image options
LargeImage:
http://ecx.images-amazon.com/images/I/41jK517l%2BBL.jpg
MediumImage: (adds '._SL160_' to the LargeImage URL)
http://ecx.images-amazon.com/images/I/41jK517l%2BBL._SL160_.jpg
SmallImage: (adds '._SL75_' to the LargeImage URL)
http://ecx.images-amazon.com/images/I/41jK517l%2BBL._SL75_.jpg
@coreyweb
coreyweb / gist:2656938
Created May 11, 2012 01:32
Show a random post from a category, excluding the current post
<?php // show a random video from the last 10 posts in the video category
$vidCount = rand(0, 9);
$my_query = new WP_Query(
array(
"cat" => 11,
"showposts" => 1,
"offset" => $vidCount,
"post__not_in" => array($post->ID) // exclude the current post from the list
@coreyweb
coreyweb / gist:2718955
Created May 17, 2012 13:33
WordPress Popular Comments
<?php
/**
* Display a list of the 10 most commented posts (WordPress)
* @author Corey Brown https://github.com/coreyweb
* @author Aaron Collegeman: https://github.com/collegeman
* @author Joey Blake: https://github.com/joeyblake
*
* Rules:
* - show a list of 10 posts
* - published any time
@coreyweb
coreyweb / gist:2732543
Created May 19, 2012 22:07
Get WP Pages by Custom Template Name
<?php /*
Get a list of all pages on a site, by their template name.
This is useful in determining which custom page templates are in use (and the reverse: which are not)
source: Jorge Pedret
http://jorgepedret.com/web-development/get-pages-by-template-name-in-wordpress/
*/
@coreyweb
coreyweb / vt_resize.php
Created May 20, 2012 17:03
WordPress Dynamic Image Resizing
<?php
/**
* Resize images dynamically using wp built in functions.
* @author Victor Teixeira http://profiles.wordpress.org/vteixeira/
* @author Aaron Collegeman http://aaroncollegeman.com
* @see http://core.trac.wordpress.org/ticket/15311
*
* @coreyweb's note: I asked Aaron to simplify Victor's original by excluding
* the lookup to see if the original image is big enough to render the newly sized image.
* Our themes don't increase image sizes (ever), and if they did, they would
@coreyweb
coreyweb / tweet linkifier
Created January 21, 2013 22:04
Convert Twitter @mentions, #hashtags and URLs within a string to anchor links.
<?php
// Convert URL's with protocol prefix
$tweet = ereg_replace("[a-zA-Z]+://([-]*[.]?[a-zA-Z0-9_/-?&%])*", "<a href=\"\\0\">\\0</a>", $tweet);
//Convert URL with just www.
$tweet = ereg_replace("(^| |\n)(www([-]*[.]?[a-zA-Z0-9_/-?&%])*)", "\\1<a href=\"http://\\2\">\\2</a>", $tweet);
//Convert # hashtags
$tweet = ereg_replace("(^| |\n)(\#([-]*[.]?[a-zA-Z0-9_/-?&%])*)", "\\1<a href=\"http://search.twitter.com/search?q=\\2\">\\2</a>", $tweet);
$tweet = str_replace("/#", "/", $tweet);
@coreyweb
coreyweb / wp_soundcloud-shortcode.php
Created June 15, 2013 17:01
Soundcloud Shortcode function for self-hosted WordPress
<?php
// Soundcloud has a shortcode for WordPress.com,
// but it doesn't work on self-hosted WordPress sites.
// To make the standard shortcode work, add this to your functions.php file.
// Here is what Soundcloud's "WordPress Code" shortcode looks like:
// [soundcloud url="http://api.soundcloud.com/tracks/95232600" params="" width=" 100%" height="166" iframe="true" /]
function soundcloud( $atts, $url='' ) {
extract(shortcode_atts(array(
'url' => 'http://',