Skip to content

Instantly share code, notes, and snippets.

View krogsgard's full-sized avatar

Brian Krogsgard krogsgard

View GitHub Profile
@krogsgard
krogsgard / custom-query-nav.php
Created February 6, 2013 19:34
Simple navigation for pagination using previous_posts_link and next_posts_link for custom WP_Query
<?php
echo '<div class="loop-nav">';
previous_posts_link( '<div class="previous">' . __( 'Newer Entries', 'your-textdomain' ) . '</div>', $my_custom_query->max_num_pages );
next_posts_link( '<div class="next">' . __( 'Older Entries', 'your-textdomain' ) . '</div>', $my_custom_query->max_num_pages );
echo '</div><!-- .loop-nav -->';
@krogsgard
krogsgard / filter-byline.php
Last active December 15, 2015 03:49
Filter byline w/ Hybrid Core
<?php
/* filter byline in hybrid core themes that utilize one
*
* Change "inforock" to your own textdomain for your theme
* Use shortcodes as shown for various byline info
* More available shortcodes can be found in Hybrid Core docs
*/
add_filter( "{$prefix}_byline", 'krogsgard_alter_byline' );
// Twitter Feed
add_shortcode( 'tweet-tweet', 'infom_get_twitter_feed' );
function infom_get_twitter_feed( $atts ) {
extract(shortcode_atts(array(
'handle' => 'krogsgard',
'count' => '1'
), $atts));
$handle = sanitize_text_field( $handle );
$count = intval( $count );
@krogsgard
krogsgard / featured-posts.php
Created March 27, 2013 16:37
Recent posts shortcode example. Inspired by Bill Erickson's excellent Display Posts shortcode.
<?php
// add shopping cart thingy
function mystore_shopping_cart() {
global $woocommerce;
?>
<aside class="header-cart-info">
<a href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="View your shopping carts" class="cart-contents">
<?php
add_action( 'pre_new_day', 'krogs_alter_new_day' );
/**
* krogs_alter_new_day function.
*
* @access public
* @param mixed $day
@krogsgard
krogsgard / wp-query-doing-it-wrong.php
Last active December 19, 2015 06:59
Don't copy this. It's just a sample of doing it wrong.
<?php
/*
* WP_Query doing_it_wrong
*
* i'm commenting this so you don't copy / paste this fail sauce
*/
$original_query = $wp_query; // YUDOTHAT???
$wp_query = null; // Oh, man
@krogsgard
krogsgard / wp-query-the-right-way.php
Last active January 4, 2021 21:59
sample custom WP_Query the right way
<?php
/*
* WP_Query happy dance
*
* this is a sample WP_Query the right way
*/
$args = array (
'post_type' => 'post',
<?php
function poststatus_get_love_it() {
if ( 'post' == get_post_type() ) {
$love_output = lip_love_it_link( $post_id = get_the_ID(), $link_text = ' <div class="genericon genericon-collapse"></div> ', $already_loved = '', $echo = false );
return $love_output;
}