Created
May 5, 2015 17:13
-
-
Save Shelob9/63e54bfbda79bd99ded8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Microblog | |
Author: Josh Pollock | |
Version: 0.1.0 | |
*/ | |
/** | |
* Make sure theme supports aside post format | |
*/ | |
add_action( 'after_setup_theme', function() { | |
$formats = get_theme_support( 'post-formats' ); | |
$formats = $formats[0]; | |
if ( ! is_array( $formats ) ) { | |
$formats = array( 'aside'); | |
}elseif( ! in_array( 'aside', $formats ) ) { | |
$formats[] = 'aside'; | |
} | |
add_theme_support( 'post-formats', $formats ); | |
}, 50 ); | |
/** | |
* Add rewrite rules for small-things microblog | |
*/ | |
add_action( 'init', function (){ | |
//pagination rule | |
add_rewrite_rule( 'small-things/page/?([0-9]{1,})/?$', 'index.php?post_format=aside&paged=$matches[1]', 'top' ); | |
//first page rule | |
add_rewrite_rule( 'small-things/?$', 'index.php?post_format=aside', 'top' ); | |
}); | |
/** | |
* Customize and shorten the asides term link. | |
*/ | |
add_filter( 'term_link', function( $termlink, $term, $taxonomy ) { | |
if ( 'post_format' == $taxonomy && 'Aside' == $term->name ) { | |
$termlink = home_url( 'small-things' ); | |
} | |
return $termlink; | |
}, 10, 3 ); | |
/** | |
* Remove asides from main blog index | |
*/ | |
add_action( 'pre_get_posts', function( $query ) { | |
if ( | |
$query->is_home() && $query->is_main_query() && | |
( ! isset( $query->query_vars[ 'post_format' ] ) || | |
( isset( $query->query_vars[ 'post_format' ] ) ) && | |
'post-format-aside' != $query->query_vars[ 'post_format' ] ) | |
) { | |
$query->set( 'tax_query', | |
array( | |
array( | |
'taxonomy' => 'post_format', | |
'field' => 'slug', | |
'terms' => array( 'post-format-aside' ), | |
'operator' => 'NOT IN', | |
) | |
) | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi, the small-things rewrite rule don't work, nor in the plugin nor on your website.
anyway, thanks for the code