Skip to content

Instantly share code, notes, and snippets.

View krogsgard's full-sized avatar

Brian Krogsgard krogsgard

View GitHub Profile
@krogsgard
krogsgard / [entry-modified] shortcode
Created February 12, 2012 19:13
Uses the get_the_modified_time function to created a shortcode, just like the [entry-published] shortcode in Hybrid Core
add_shortcode( 'entry-modified', 'krogs_entry_modified_shortcode' );
function krogs_entry_modified_shortcode( $attr ) {
$domain = hybrid_get_textdomain();
$attr = shortcode_atts( array( 'before' => '', 'after' => '', 'format' => get_option( 'date_format' ) ), $attr );
$modified = '<abbr class="modified" title="' . sprintf( get_the_modified_time( esc_attr__( 'l, F jS, Y, g:i a', $domain ) ) ) . '">' . sprintf( get_the_modified_time( $attr['format'] ) ) . '</abbr>';
return $attr['before'] . $modified . $attr['after'];
@krogsgard
krogsgard / wordpress-loop
Created February 20, 2012 04:45
The Basic WordPress Loop
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php // You can do stuff here to display aspects of the posts which meet the criteria of the current loop. ?>
<?php endwhile; else: ?>
<p><?php _e('The Loop did not find anything.'); ?></p>
<?php endif; ?>
@krogsgard
krogsgard / arcticle
Created February 21, 2012 02:06
Twenty Eleven Loop
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
@krogsgard
krogsgard / wp-trim-words-example
Created February 23, 2012 05:34
Example query using wp_trim_words()
<div class="info-box">
<?php $krogsquery = new WP_Query( array(
'post_type' => 'post',
'posts_per_page' => 3
)); ?>
<h3 class="info-headline">City News</h3>
<?php while($krogsquery->have_posts()) : $krogsquery->the_post(); ?>
@krogsgard
krogsgard / query-posts-page-template
Created March 7, 2012 05:07
query_posts in page template
<?php $args = array(
'post_type' => array ( 'post', 'page' ),
'posts_per_page' => 1,
'paged' => ( get_query_var('page') ? get_query_var('page') : 1 )
); ?>
<?php query_posts( $args ); ?>
<?php if ( have_posts() ) : ?>
@krogsgard
krogsgard / enqueue-scripts.php
Created May 15, 2012 02:23
Sample enqueue scripts action and function
<?php
/*
* WordPress Sample function and action
* for loading scripts in themes
*/
// Let's hook in our function with the javascript files with the wp_enqueue_scripts hook
add_action( 'wp_enqueue_scripts', 'wpcandy_load_javascript_files' );
@krogsgard
krogsgard / custom-field-advanced-body-class.php
Created June 20, 2012 16:57
add a body class based on a post's custom field value
<?php
// check for '_my_custom_field' meta key on pages and page parents and add a body class if meta value equals 'some-value'
add_filter('body_class','krogs_custom_field_body_class');
function krogs_custom_field_body_class( $classes ) {
global $post;
<?php
/**
* Add function to widgets_init that'll load our widget.
* @since 0.1
*/
add_action( 'widgets_init', 'latest_load_widgets' );
/**
* Register our widget.
* 'Latest_Tweet_Widget' is the widget class used below.
@krogsgard
krogsgard / events-labels.php
Created June 22, 2012 16:03
Change The Events Calendar labels
<?php
add_filter( 'gettext', 'krogs_event_change_venue_name', 20, 3 );
/**
* Change comment form default field names.
*
* @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
*/
function krogs_event_change_venue_name( $translated_text, $text, $domain ) {
@krogsgard
krogsgard / list-terms-shortcode.php
Created June 24, 2012 23:23
shortcode list taxonomy terms
<?php
/**
* Displays a list of terms for a specific taxonomy.
* Based on Justin Tadlock's [entry-terms] shortcode
* Added attribute to not link to the taxonomy
* using wp_get_object_terms() to do so
*
* @author Brian Krogsgard
*
* @access public