Skip to content

Instantly share code, notes, and snippets.

@timwco
timwco / HTTP Authenticate
Created February 13, 2011 03:20
Authenticate HTTP Request
before_filter :httpauth
private
def httpauth
authenticate_or_request_with_http_basic do |user, password|
user == 'userName' && password == 'crazyLongPassword1234'
end
end
@timwco
timwco / gist:830155
Created February 16, 2011 20:43
Facebook XML - Like Pull
$xml_string = 'http://domain.com/sitemap.xml';
//load the xml string using simplexml
$xml = simplexml_load_file($xml_string);
//loop through the each node of user
$results = array();
foreach($xml->url as $url){
@timwco
timwco / gist:831960
Created February 17, 2011 15:50
Wordpress - Custom Post Loop
<?php $loop = new WP_Query( array( 'post_type' => 'custom_post_type_name', 'posts_per_page' => 100 ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="post">
<?php the_post_thumbnail(); ?>
<div class="postInfo">
<h3 class="lgr"><?php the_title() ?></h3>
<a href="<?php the_permalink() ?>">Read More</a>
</div>
</div>
<?php endwhile; ?>
@timwco
timwco / roundedNumber.php
Created March 21, 2011 20:13
Wordpress - Get # of Posts and Round to Nearest Hundred
<?php
function get_rounded_number_of_posts() {
$count_posts = wp_count_posts();
$numposts = $count_posts->publish;
if (strlen($numposts)<3) {
$numposts = $numposts;
} else {
$numposts=substr($numposts, 0, strlen($numposts)-2) . "00";
}
return $numposts;
@timwco
timwco / gist:1008959
Created June 5, 2011 13:27
Wordpress Apply to All Sub Pages
<?php
if ( is_page('about-us') || '3' == $post->post_parent ) {
// Do Something SPECIFIC Here
} else {
// Handle Everything Else Here
}
?>
@timwco
timwco / gist:1020229
Created June 11, 2011 03:44
Custom Icon in Wordpress Admin
<?php
function as_custom_logo() {
echo '
<style type="text/css">
#header-logo { background-image: url('.get_bloginfo('template_directory').'/images/myIcon.png) !important; }
</style>
';
}
@timwco
timwco / gist:1685021
Created January 26, 2012 20:50
Adjust Default Tags Widget
<?php
add_filter( 'widget_tag_cloud_args', 'my_widget_tag_cloud_args' );
function my_widget_tag_cloud_args( $args ) {
$args['number'] = 20;
$args['largest'] = 9;
$args['smallest'] = 9;
$args['unit'] = 'px';
$args['exclude'] = array(20, 80);
return $args;
@timwco
timwco / gist:2081620
Created March 18, 2012 21:31 — forked from luetkemj/wp-query-ref.php
WP: Query $args
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query
* Source: http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/query.php
*/
$args = array(
@timwco
timwco / remove_post_by_author.sql
Created April 21, 2012 15:12
Remove All Post & Post Meta By Author - WordPress
DELETE a,b,c FROM `wp_posts` a
LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)
LEFT JOIN wp_postmeta c ON (a.ID = c.post_id)
WHERE a.post_author = '0';
@timwco
timwco / gist:9212770
Last active August 29, 2015 13:56
Show/Hide Barley Icon - http://getbarley.com
// Hide the Barley Icon by default
// Show the Barley Icon on ESC Key Press
// Make sure DOM is loaded
document.addEventListener('DOMContentLoaded', function(){
// The Barley Icon Element
var barleybar = document.getElementById('barley-bar');
// Hide By Default