Skip to content

Instantly share code, notes, and snippets.

@ericpedia
Created November 7, 2011 22:11
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 ericpedia/1346372 to your computer and use it in GitHub Desktop.
Save ericpedia/1346372 to your computer and use it in GitHub Desktop.
fig shortcode
<?php
function epi_FiguresTablesCharts_shortcode ( $atts, $content=null ) {
extract( shortcode_atts( array(
'label' => null,
'url' => null,
'style' => null,
'width' => null,
'hidelabel' => null,
'inline' => null,
), $atts ) );
$view = $_GET["view"];
$this_is_inline = null;
$this_is_inline = ( $content && strpos( $content, '<table' ) ) ? 'fig-inline' : null ;
$this_is_an_image = null;
// Check if there is a URL present
// (We can't use if (strpos( $url, 'http' )) because it returns 0, which evaluates to false)
$this_is_an_image = ($url && strpos( $url, 'ttp') ) ? 'fig-image' : null;
// $this_is_an_image = ($url && strpos( $url, 'ttp') && ( strlen($content) <= 3 ) ) ? 'fig-image' : null;
if ( $this_is_an_image || $this_is_inline ) {
// Set the image size and CSS class
if ( $width == 'half' ) {
$w = '360';
$c = ' halfright';
} else {
$w = ($label && $hidelabel != 'true') ? '588' : '608';
if ( get_post_type() == 'blog' ) {
$w = '536';
}
$c = '';
}
// If it has a label, wrap it in a border
if ( $label && !$hidelabel ) {
$before = '<div class="clearfix figure'. $c .'"><div class="figurelabel bg-gradient">' . $label . '</div>';
$after = '<div class="bg-gradient fig-after"></div></div>';
} else {
$before = null;
$after = null;
}
// Set up the figure tag
if ( $this_is_inline ) {
$figure = $before;
$figure .= $content;
$figure .= $after;
} else {
if ( $view == "print" ) {
$figure = $before;
$figure .= '<img src="' . $url . '" alt="' . $label . '">';
$figure .= $after;
} else {
$figure = $before;
$figure .= '<img src="' . get_site_url() . '/m/?src=' . $url . '&w=' . $w . '" alt="' . $label . '">';
$figure .= $after;
}
}
// If there's no figure URL and no wrapped content, return nothing
} else {
$figure = null;
}
return $figure;
}
add_shortcode( 'fig', 'epi_FiguresTablesCharts_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment