Skip to content

Instantly share code, notes, and snippets.

@scrobbleme
Created September 6, 2016 08:38
Show Gist options
  • Save scrobbleme/38da79faa58f6b79a353f11468b14d85 to your computer and use it in GitHub Desktop.
Save scrobbleme/38da79faa58f6b79a353f11468b14d85 to your computer and use it in GitHub Desktop.
A simple shortcode to replace NextGens singlepic shortcode. You still need to have the nextgen tables within your database.
<?php
/**
* This is a replacement for NextGens "singlepic" shortcode
*/
add_shortcode('singlepic', 'render_shortcode_nextgen_singlepic_replacement');
function render_shortcode_nextgen_singlepic_replacement($attributes = array()) {
/** @global wpdb $wpdb */
global $wpdb;
$attributes = shortcode_atts(array(
'id' => -1,
'w' => -1,
'h' => -1,
), $attributes);
if ($attributes['id'] == -1) {
return __('Image not defined', 'textdomain');
}
$image = $wpdb->get_row('SELECT galleryid, filename FROM ' . $wpdb->prefix . 'ngg_pictures WHERE pid=' . intval($attributes['id']));
if (!$image || $image == null) {
return __('Image not found', 'textdomain');
}
$gallery = $wpdb->get_row('SELECT path FROM ' . $wpdb->prefix . 'ngg_gallery WHERE gid=' . intval($image->galleryid));
if (!$gallery || $gallery == null) {
return __('Gallery not found', 'textdomain');
}
$style = '';
if (intval($attributes['h']) > 0) {
$style .= 'height: ' . intval($attributes['h']) . ' ;';
}
if (intval($attributes['w']) > 0) {
$style .= 'width: ' . intval($attributes['w']) . ' ;';
}
return '<img id="nextgen-origin-' . intval($attributes['id']) . '"style="' . $style . '" src="' . get_site_url() . '/' . $gallery->path . '/' . $image->filename . '" />';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment