Skip to content

Instantly share code, notes, and snippets.

@micahwave
micahwave / gist:1996643
Created March 7, 2012 22:20
newsfeed posts by sean
$q = new WP_Query(
array(
'posts_per_page' => -1,
'post__not_in' => array( 1368 ), // skipping http://newsfeed.time.com/2010/05/17/taste-testing-the-worlds-most-alcoholic-beer/
'post_status' => 'publish',
'post_type' => 'post',
'author' => 14074318,
)
)
@micahwave
micahwave / gist:2024189
Created March 12, 2012 19:31
bitly processs
/**
* Cron to process all of the posts that don't have bitly urls
*/
function time_process_bitly() {
global $wpdb;
// get 100 published posts that don't have a bitly url
$query = $wpdb->prepare(
"
<media-reference id="media-reference:b1ae49b273d2e307090f6a70670057e5" mime-type="image/jpeg" name="AP Thumbnail Image" source="http://eapcontent.ap.org/jpg/2012/20120314/11/b1ae49b273d2e307090f6a70670057e5.jpg?contentid=b1ae49b273d2e307090f6a70670057e5/fmt=jpg/role=Thumbnail/reldt=2012-03-14T11:05:58/media=Photo/recordid=5ba9fcac175943c58a2915a3ca65020b/authToken=eNoFwrEKwzAMBcAvsnmyLakeNHbI0K3QsdiJAtkMoSSDP77cTb9NchHlykACQPSguR7WqXmpPQXNWwqeoQEVe5CmEAVYnefvtPfyei7fj%2ffdfTvnuKwNIpnHsEQSM0ctsfwBxaUc9Q%3d%3d&amp;token=1331998202_46B3C20C9EE3641CADC69F406362AAD9" alternate-text="John Bishop" height="83" width="128" coding="jpg" />
@micahwave
micahwave / gist:2161421
Created March 22, 2012 18:39
bitly shortlink
/**
* Helper function to get the short url for a post
*
* @param int $post_id
* @return string $url
*/
function time_get_bitly_url( $post_id = null ) {
$post_id = empty( $post_id ) ? get_the_ID() : $post_id;
@micahwave
micahwave / gist:2629127
Created May 7, 2012 17:28
wp_query, first post, last post
function time_first_post() {
global $wp_query;
return ( in_the_loop() && $wp_query->current_post == 0 );
}
function time_last_post() {
global $wp_query;
return ( in_the_loop() && $wp_query->current_post == $wp_query->post_count-1 );
}
@micahwave
micahwave / gist:2630535
Created May 7, 2012 21:19
wp_query derp
// backend, gather the data
if( have_posts() ) {
get_template_part( 'derp' );
}
wp_reset_query();
// front-end, derp.php
<?php while( have_posts() ) : the_post(); ?>
@micahwave
micahwave / gist:2712965
Created May 16, 2012 18:50
package migrate
function migrate_old_package( $post_id ) {
global $wpdb;
// fix all the slides
$slides = $wpdb->get_results( $wpdb->prepare("
SELECT * FROM $wpdb->posts AS s WHERE s.post_type = 'time_slide' AND s.post_parent = $post_id
"));
foreach( $slides as $slide ) {
<article id="article-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h3 class="entry-category">Category</h3>
<h1 class="entry-title">Article Title</h1>
<div class="entry-meta">
<span class="entry-byline">By Author</span>
<span class="entry-data">Date</span>
@micahwave
micahwave / gist:2948501
Created June 18, 2012 13:58
WP-Paginate markup
<ol class="wp-paginate">
<li><span class="title"></span></li>
<li><span class="page current">1</span></li>
<li><a href="http://micahland.com/page/2/" title="2" class="page">2</a></li>
<li><a href="http://micahland.com/page/3/" title="3" class="page">3</a></li>
<li><a href="http://micahland.com/page/4/" title="4" class="page">4</a></li>
<li><a href="http://micahland.com/page/5/" title="5" class="page">5</a></li>
<li><span class="gap">...</span></li>
<li><a href="http://micahland.com/page/8/" title="8" class="page">8</a></li>
<li><a href="http://micahland.com/page/2/" class="next">Next</a></li>
@micahwave
micahwave / gist:2961583
Created June 20, 2012 19:01
Package markup
<div class="time-gallery package">
<div class="nav">
<a href="#" class="disabled arrow prev">prev</a>
<div style="float:left">
<div class="count" style="float:none;">
<span class="position">1</span>