Skip to content

Instantly share code, notes, and snippets.

Avatar

Brian Krogsgard krogsgard

View GitHub Profile
@krogsgard
krogsgard / [entry-modified] shortcode
Created Feb 12, 2012
Uses the get_the_modified_time function to created a shortcode, just like the [entry-published] shortcode in Hybrid Core
View [entry-modified] shortcode
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 Feb 20, 2012
The Basic WordPress Loop
View 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 Feb 21, 2012
Twenty Eleven Loop
View arcticle
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
@krogsgard
krogsgard / wp-trim-words-example
Created Feb 23, 2012
Example query using wp_trim_words()
View wp-trim-words-example
<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 Mar 7, 2012
query_posts in page template
View query-posts-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
Sample enqueue scripts action and function
View enqueue-scripts.php
<?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 Jun 20, 2012
add a body class based on a post's custom field value
View custom-field-advanced-body-class.php
<?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;
View tweet-widget.php
<?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 Jun 22, 2012
Change The Events Calendar labels
View events-labels.php
<?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 Jun 24, 2012
shortcode list taxonomy terms
View list-terms-shortcode.php
<?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