Skip to content

Instantly share code, notes, and snippets.

View coreyweb's full-sized avatar

corey brown coreyweb

View GitHub Profile
@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: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: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 / 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: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 / 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:2194861
Created March 25, 2012 14:02
Custom 404 (Mod Rewrite)
ErrorDocument 404 /404.php
@coreyweb
coreyweb / gist:2194845
Created March 25, 2012 14:02
Force www (mod rewrite)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain-name\.com
RewriteCond %{HTTPS} =on
RewriteRule .* https://www.%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteCond %{HTTP_HOST} ^domain-name\.com
RewriteCond %{HTTPS} !=on
RewriteRule .* http://www.%{SERVER_NAME}%{REQUEST_URI} [R,L]
@coreyweb
coreyweb / gist:2194781
Created March 25, 2012 14:00
Twitter: rewrite URLs and replies as links
<?php
// Convert URL's with protocol prefix
$text = ereg_replace("[a-zA-Z]+://([-]*[.]?[a-zA-Z0-9_/-?&%])*", "<a href=\"\\0\">\\0</a>", $text);
//Convert URL with just www.
$text = ereg_replace("(^| |\n)(www([-]*[.]?[a-zA-Z0-9_/-?&%])*)", "\\1<a href=\"http://\\2\">\\2</a>", $text);
//Convert @ replies
$text = ereg_replace("(^| |\n)(\@([-]*[.]?[a-zA-Z0-9_/-?&%])*)", "\\1<a href=\"http://www.twitter.com/\\2\">\\2</a>", $text);
$text = str_replace("/@", "/", $text);
@coreyweb
coreyweb / gist:2194743
Created March 25, 2012 13:58
PHP Randomizer
<?php
// Set the lowest & highest numeric point in you series names of your includes files - example here is 1 and 4
$sl = rand(1,4);
echo $sl;
?>