WordPress.org

Forums

Really Simple Gallery Widget
[resolved] Show in image.php (4 posts)

  1. lolwp
    Member
    Posted 2 years ago #

    Hi,

    is there any way for the widget to show other attached images from parent post in widget when viewing the image attachment (image.php)?

    I don't know any PHP but if it's a fairly simple change I can copy/paste code if you provide it and change the plugin myself.

    Thanks

    http://wordpress.org/extend/plugins/really-simple-gallery-widget/

  2. Helen Hou-Sandi
    WordPress Dev
    Plugin Author

    Posted 2 years ago #

    Please don't change the plugin code itself - there are hooks provided for you to alter behavior. Altering a plugin or theme directly is never a good idea, as your changes will get wiped out with an update. This should work, in something like the theme's functions.php file (if it's your own theme) or a custom plugin file:

    add_filter( 'rsgw_query_args', 'hhs_attachment_page_rsgw_query_args', 10, 2 );
    function hhs_attachment_page_rsgw_query_args( $query_args, $args ) {
    	global $post;
    
    	if ( 'attachment' == get_post_type() && ! empty( $post->post_parent ) ) {
    		$query_args['post_parent'] = $post->post_parent;
    	}
    
    	return $query_args;
    }
  3. lolwp
    Member
    Posted 2 years ago #

    Thank you for your response, I could never figure out something like that on my own. Worked perfectly.

    Just took me about 3 hours to figure out how to display your plugin's widget only when viewing the attachment page. This is the best I could come up with, creating new widget areas and:

    <?php if (is_attachment() ) : ?>
    <?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('more-images') ); ?>
               <?php else : ?>
    <?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('not-attachment') ); ?>
    
    	<?php endif; ?>

    I don't need it (anymore), but perhaps it's a feature you might want to consider for your plugin.

    Again, thanks for your help.

  4. bigu_c
    Member
    Posted 1 year ago #

    Hi Helen Hou-Sandi,

    Your code work fine for me.

    But how to exclude current image? (current image will not display on sidebar?

    Thank you.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Really Simple Gallery Widget
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.