Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author phoenixMagoo

    (@phoenixmagoo)

    Hey,

    This plugin only works on pages or posts that contain the gallery short code. I’m pretty sure that you would need to add the masonry effect on the attachment page through your functions.php and by creating a new js file. This is what I would do.

    Create a new js file and save it to your theme’s, or child theme’s, directory. Put this code in the new js file:

    (function($){
    	var $container = $('.gallery');
    		$container.imagesLoaded(function(){
    			$container.masonry({
    				itemSelector : '.gallery-item',
    				isAnimated: true,
    					animationOptions: {
    						duration: 250,
    					 	easing: 'linear',
    					 	queue: false
    					 },
    				isFitWidth: true
    				});
    			});
    })(jQuery);

    In your functions.php file do something like this to include the js file you just created. This will also make sure only to add it in on attachment pages:

    function masonry_attachment_page() {
    	wp_enqueue_script(
    		'attachment-masonry',
    		get_stylesheet_directory_uri() . 'NEW-JS-File.js',
    		array( 'jquery' )
    	);
    }
    
    if ( is_attachment() ) {
    
    add_action( 'wp_enqueue_scripts', 'masonry_attachment_page' ); 
    
    }

    Then the last step would be making sure to add in the correct CSS. In your style.css file, put in:

    .gallery-item {width: 300px !important}

    That should work. I haven’t tested the code, let me know how it works for you!

    Thread Starter poemaxx

    (@poemaxx)

    Hi Phoenix,

    Thanks very much for your ocmprehensive reply. Unfortunately, it still doesn’t seem to be working.

    I created a js file in the child theme directory, copied in your code and saved it as masonryfix.js. (Incidentally, although I can see this file on the server, I can’t see it listed under the templates on the Edit Themes page in WordPress – I don’t know if this is significant.)

    I created a new functions.php in the child theme directory and copied in your code, changing ‘NEW-JS-File.js’ to ‘masonryfix.js’.

    Then I added the .gallery-item code into the child theme CSS file. The only thing that appears to have happened is that all the thumbnails are now in a single column. ??

    Am I doing something wrong?

    Plugin Author phoenixMagoo

    (@phoenixmagoo)

    Hey,

    It doesn’t look like the plugin is firing on the attachment page. I can’t see any Masonry calls in the code. Please erase the CSS and that should fix the problem for now.

    I will try to spend a little time this weekend problem solving this for you.

    Thread Starter poemaxx

    (@poemaxx)

    OK – have removed the CSS stuff and now back to three columns.

    Thanks so much for helping with this – I really appreciate it!

    Plugin Author phoenixMagoo

    (@phoenixmagoo)

    Could you try this for me? On line 97 in the init.php file, change this:

    if( has_shortcode( $post->post_content, 'gallery') ) {

    to:

    if( has_shortcode( $post->post_content, 'gallery') or is_attachment() ) {

    and change line 120 to:

    if( has_shortcode( $post->post_content, 'gallery') or is_attachment() ) {

    This should work based on all the documentation I’ve looked at dealing with conditional statements and attachment pages.

    Also, does your theme have a specific template for attachments?

    Thread Starter poemaxx

    (@poemaxx)

    OK – done that. It does look as if Masonry is now being called up on the attachment page, but the only difference it’s made is that the thumbnails revert to single column (I haven’t added the new CSS code again).

    The theme does have a specific template for attachments – would it help if you had the code for this?

    Plugin Author phoenixMagoo

    (@phoenixmagoo)

    Ok. Awesome. Good news and bad news.

    The bad news: The plugin is not going to work correctly on your attachment page since the plugin pulls in the width of the thumbnail dimensions from the Media settings page. That’s why the size of the thumbnails on the attachment page are 300px wide.

    The good news: This is a really simple plugin and it should be really easy to add to your theme. I have a tutorial located here .

    If you include Masonry in the non-plugin way, you should be able to specify the thumbnail width manually for the gallery pages and attachment pages.

    For example you could put this PHP in at the bottom of your <head> to define the width of the thumbnails on their respective pages:

    <?php global $post; if ( has_shortcode( $post->post_content, 'gallery') ) : ?>
    
    	<style type="text/css">
    
    		.gallery-item {width: 300px !important}
    
    	</style>
    
    <?php elseif ( is_attachment() ) : ?>
    
    	<style type="text/css">
    
    		.gallery-item {width: 150px !important}
    
    	</style>
    
    <?php endif ; ?>

    Hope this helps!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Not working on attachment page’ is closed to new replies.