Skip to content

Instantly share code, notes, and snippets.

@theukedge
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theukedge/9146805 to your computer and use it in GitHub Desktop.
Save theukedge/9146805 to your computer and use it in GitHub Desktop.
<?php // SPECIAL FEATURE CONTENT SHORTCODE
function hpc_special_feature_shortcode( $atts ) {
extract( shortcode_atts(
array(
'type' => '',
'showposts' => -1,
'feature' => '',
'cat' => '',
'offset' => '',
'layout' => 'bullets'
), $atts )
);
$hpc_special_feature_query = get_transient( 'hpc_special_feature_query_' . $type . '_' . $showposts . '_' . $feature . '_' . $cat . '_' . $offset );
if( $hpc_special_feature_query === false ) {
$hpc_special_feature_query = new WP_Query( array(
'post_type' => $type,
'showposts' => $showposts,
'tax_query' => array(
array(
'taxonomy' => 'special-feature',
'field' => 'slug',
'terms' => $feature
)
),
'category_name' => $cat,
'offset' => $offset
) );
set_transient( 'hpc_special_feature_query_' . $type . '_' . $showposts . '_' . $feature . '_' . $cat . '_' . $offset, $hpc_special_feature_query, 60*3 );
}
ob_start(); ?>
<div class="<?php echo $feature; ?>-content <?php echo $type; ?> <?php echo $layout; ?>">
<?php if( $layout == 'bullets' ) { ?>
// BULLETS LOOP - NOT IMPORTANT FOR EXAMPLE
<?php } elseif( $layout == 'small-feature' ) { ?>
// SMALL FEATURE LOOP - NOT IMPORTANT FOR EXAMPLE
<?php } elseif( $layout == 'big-feature' ) { ?>
// BIG FEATURE LOOP - NOT IMPORTANT FOR EXAMPLE
<?php } elseif( $layout == 'small-excerpt' ) { ?>
// SMALL EXCERPT LOOP - NOT IMPORTANT FOR EXAMPLE
<?php } ?>
</div>
<?php $output = ob_get_contents();
ob_end_clean();
return $output;
wp_reset_postdata();
}
add_shortcode( 'special-feature-content', 'hpc_special_feature_shortcode' );
@sc0ttkclark
Copy link

Why return $output and then have wp_reset_postdata after that? Doesn't that defeat the purpose?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment