Created
January 30, 2012 23:58
-
-
Save GaryJones/1707649 to your computer and use it in GitHub Desktop.
Add post_terms shortcode (Genesis pre-1.4.2)
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 | |
add_shortcode( 'post_terms', 'child_post_terms_shortcode' ); | |
/** | |
* Add linked post taxonomy terms via shortcode. | |
* | |
* Not needed since Genesis 1.4.2 as it exists in Genesis. | |
* @author Ade Walker and Gary Jones | |
* @link http://code.garyjones.co.uk/post-taxonomy-terms-shortcode/ | |
* | |
* @global mixed $post | |
* | |
* @param array $atts Array of shortcode attributes. | |
* | |
* @return string HTML markup of terms list | |
*/ | |
function child_post_terms_shortcode( $atts ) { | |
global $post; | |
// Define some default values - separator, content before list, | |
// content after list, and which taxonomy we want. | |
$defaults = array( | |
'sep' => ', ', | |
'before' => __( 'Filed Under: ', 'genesis' ), | |
'after' => '', | |
'taxonomy' => 'category', | |
); | |
// Fill in values not provided in the shortcode, with the default values. | |
$atts = shortcode_atts( $defaults, $atts ); | |
// Create variables out of each array key, equal to the array value. | |
extract( $atts ); | |
// Get all the terms as links, from the taxonomy, for this post. | |
$terms = get_the_term_list( $post->ID, $taxonomy, $before, trim( $sep ) . ' ', $after ); | |
// Continue only if we've not hit an error when getting the terms. | |
if ( is_wp_error( $terms ) ) | |
return false; | |
// Only show output if terms were found for that taxonomy. | |
if ( empty( $terms ) ) | |
return false; | |
// Add a wrapper around our terms to make styling easier. | |
$output = '<span class="terms">' . $terms . '</span>'; | |
// Allow the output to be filtered, before returning it. | |
return apply_filters( 'genesis_post_terms_shortcode', $output, $terms, $atts ); | |
} |
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
[post_terms] |
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
[post_terms taxonomy="post_tag" before="Tagged with: "] |
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
[post_terms taxonomy="services" before="Services used on this project: "] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment