Topic: How to not display full simpleviewer gallery on front page

Hello,

I am upgrading my website from a collection of static pages  to dynamic pages  using Tempera theme of Wordpress. I successfully uploaded image gallery created in free version of simpleviewer in Wordpress blog post. However, entire gallery appears on the home page http://theoff.info/Adventure-Travel/, which I do not want.

I just want to display either thumbnail of the gallery or featured image of the blog post on the home page. Could you help me in hiding the gallery from the home page?

Thanks

Last edited by TO ABHA (2014-10-26 11:40:39)

Re: How to not display full simpleviewer gallery on front page

If you want your galleries to be embedded only in their individual pages and not on your main overview page, then open the 'wp-simpleviewer.php' file in a plain text editor and change the shortcode_handler function (on lines 256-304) to the following:

/**
 * Shortcode handler
 *
 * @param array attributes
 * @return string embed code
 */
function shortcode_handler($atts) {
    extract(shortcode_atts(array('gallery_id'=>'0'), $atts));
    $clean_gallery_id = intval($this->clean_integer($gallery_id));
    if ($clean_gallery_id > 0) {
        $gallery_path = $this->get_gallery_path();
        $gallery_filename = $gallery_path . $clean_gallery_id . '.xml';
        if (file_exists($gallery_filename)) {
            $custom_values = $this->get_custom_values($gallery_filename);
            $gallery_title = htmlspecialchars($custom_values['title']);
            $display_title = !empty($gallery_title) ? $gallery_title : 'Untitled';
            if (is_singular()) { // Embed the gallery only if the post is being displayed on its individual page.
                $gallery_width = $custom_values['e_g_width'];
                $gallery_height = $custom_values['e_g_height'];
                $background_color = $custom_values['e_bgColor'];
                $use_flash = $custom_values['e_useFlash'];
                $gallery_url = plugins_url('config.php?gallery_id=' . $clean_gallery_id, __FILE__);
                $string_builder = '<!--START SIMPLEVIEWER EMBED-->' . PHP_EOL;
                $string_builder .= '<script type="text/javascript">' . PHP_EOL;
                $string_builder .= '    var flashvars' . $clean_gallery_id . ' = {};' . PHP_EOL;
                $string_builder .= '    flashvars' . $clean_gallery_id . '.galleryURL = "' . $gallery_url . '";' . PHP_EOL;
                $string_builder .= '    simpleviewer.ready(function() {' . PHP_EOL;
                $string_builder .= '        simpleviewer.load("sv-container-' . $clean_gallery_id . '", "' . $gallery_width . '", "' . $gallery_height . '", "' . $background_color . '", ' . $use_flash . ', flashvars' . $clean_gallery_id . ');' . PHP_EOL;
                $string_builder .= '    });' . PHP_EOL;
                $string_builder .= '</script>' . PHP_EOL;
                $string_builder .= '<div id="sv-container-' . $clean_gallery_id . '"></div>' . PHP_EOL;
                $string_builder .= '<!--END SIMPLEVIEWER EMBED-->' . PHP_EOL;
                return $string_builder;
            } else {
                // The following line returns HTML code to display alternate content to the embedded gallery.
                return '<div><a href="' . get_permalink() . '" title="View Post">' . get_the_post_thumbnail() . '</a></div>' . PHP_EOL;
            }
        } else {
            return '<div><p>SimpleViewer Gallery Id ' . $clean_gallery_id . ' has been deleted.</p></div>' . PHP_EOL;
        }
    } else {
        return '<div><p>SimpleViewer Gallery Id cannot be found.</p></div>' . PHP_EOL;
    }
}

On the main overview page, the code above displays the post's featured image as a link to the post's individual page (instead of the embedded gallery). You can change this alternate content to whatever you like (e.g. text rather than the featured image).

Please note that the line numbers above refer to the current version of WP-SimpleViewer (v2.3.2.4).

Steven Speirs
SimpleViewer Support Team.

Re: How to not display full simpleviewer gallery on front page

Thanks Steven Speirs!

The solution provided works with the galleries created using wp-simpleviewer plugin.

But I have uploaded old galleries (which I do not want to recreate) using Kimi flash embed plugin as mentioned on http://simpleviewer.net/simpleviewer/su … #wordpress.

Could you tell me where to add the revised short_code handler function in Kimi flash embed plugin files to achieve the desired results?

Kind Regards

Re: How to not display full simpleviewer gallery on front page

I am not familiar with the Kimili plugin and, unfortunately, their website seems to be down at the moment (with a "Database unavailable." message) so I am unable to download the plugin and examine its code.

The key is to wrap the embedding code in the shortcode handler function within the following structure:

if (is_singular()) {
    // Embedding code (for singular pages) goes here
} else {
    // Alternate code (for main overview page) goes here
}

The WordPress function is_singular() will be true only if a single post is being displayed on the current page.

You should be able to find the name of the plugin's shortcode handler function from the add_shortcode() function. Search for add_shortcode and the name of the function will be the second parameter. You can then search for the name of the function and modify its code as required.

All the above assumes that the Kimili plugin uses a shortcode. If it simply outputs the embedding code directly into the body of the post, then what you are looking do do would not be possible (without rewriting the plugin to use a shortcode so that WordPress can treat it differently in different pages).

Steven Speirs
SimpleViewer Support Team.

Re: How to not display full simpleviewer gallery on front page

Thanks Steven Speirs for help!

Kimili plugin does not have a short code. It directly embeds flash code in the post. So I have to recreate the old galleries.

Regards