1

I am running a site (D7.43, jQuery 1.10), with the jollyany (bootstrap) theme as the basis. Among other things the site has several image galleries, generated through Views. The set up is as follows: There is a content type called Projects, where you first enter a square picture, then any number of photos that form the actual gallery.

On the galleries page (have a look: http://wixschool.net/image-gallery) Views and masonry then generate an overview of all galleries (projects) that have been created, showing the square image + with mouseover and button etc. Click on one of them, and you are presented with that individual gallery, for example: http://wixschool.net/image-gallery/peace-mile-run-battersea-park.

What I want to do now is take an individual gallery, and show that on a single page somewhere as a block. That means I want to click on a link, and end up on a page that has the slider of that gallery as one part of its content, and skipping the masonry overview.

I can and have create(d) a block, but then end up with that block showing the masonry gallery (even if filtered to just the one gallery I want). I then have to click on the gallery, which opens a new full node (page) with just that gallery and nothing else.

I assume its a Views thing, contextual filters? Any help / instructions / solutions very very welcome!

Edit: the template that runs the Image Gallery (Project) page is node--projects.tpl.php:

<?php
    /**
     * @file
     * jollyany's theme implementation to display a single Portfolio node.
     */
    global $base_url; 
    global $image_default; 

    // Grabs the firsts image path and sets $imagePath.
    $imagePath = $image_default;
    if(isset($node->field_image['und'])) {
        $imagePath = file_create_url($node->field_image['und'][0]['uri']); 
    }

    $next = jollyany_pagination($node, 'n');
    $prev = jollyany_pagination($node, 'p');

    if ($next != NULL) { 
      $next_url = url('node/' . $next, array('absolute' => TRUE));
    }

    if ($prev != NULL) { 
      $prev_url = url('node/' . $prev, array('absolute' => TRUE));
    }

    $image_slide = "";

    if ($items = field_get_items('node', $node, 'field_gallery')) {
      if (count($items) == 1) {
        $image_slide = 'false';
      }
      elseif (count($items) > 1) {
        $image_slide = 'true';
      }
    }

    $img_count = 0;
    $counter = count($items);

    $termid = arg(2);
?>

<?php if (!$page) : ?>
    <?php if( !empty($termid) ) : ?>
        <div class="col-lg-4">
    <?php endif; ?>
        <div class="portfolio_item">
            <div class="entry">
                <img src="<?php echo $imagePath; ?>" alt="" class="img-responsive">
                <div class="magnifier">
                    <div class="buttons">
                        <a class="st btn btn-default" rel="bookmark" href="<?php echo $node_url; ?>"><?php print theme_get_setting('project_text_button'); ?></a>
                        <h3><?php print $title; ?></h3>
                    </div>
                </div>
            </div>
        </div>
    <?php if( !empty($termid) ) : ?>
        </div>
    <?php endif; ?>
<?php else :?>
    <div class="row">
    <?php if(isset($node->field_layout['und']) && $node->field_layout['und'][0]['taxonomy_term']->name == 'Sidebar') :?>
            <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 single-portfolio">
                <div class="col-sm-7 padding-left-0">
                    <?php if(isset($node->field_video['und']) && !empty($node->field_video['und'][0]['value'])) :?>
                        <div class="portfolio_item">
                            <div class="entry">
                                <?php print $node->field_video['und'][0]['value']; ?>
                                <div class="post-type">
                                    <i class="fa fa-play"></i>
                                </div>
                            </div>
                        </div>
                    <?php elseif(isset($node->field_audio['und']) && !empty($node->field_audio['und'][0]['value'])) :?>
                        <div class="portfolio_item">
                            <div class="entry">
                                <?php print $node->field_audio['und'][0]['value']; ?>
                                <div class="post-type">
                                    <i class="fa fa-music"></i>
                                </div>
                            </div>
                        </div>
                    <?php elseif($image_slide != '') : ?>
                        <div id="aboutslider" class="flexslider clearfix">
                            <ul class="slides">
                                <?php while ($img_count < $counter) { ?>
                                    <?php /*?><li><img src="<?php echo image_style_url('image_650x312',$node->field_gallery['und'][$img_count]['uri']); ?>" class="img-responsive" alt=""></li><?php */?>
                                   <li><img src="<?php echo file_create_url($node->field_gallery['und'][$img_count]['uri']); ?>" class="img-responsive" alt=""></li>


                                <?php $img_count++; } ?>
                                <?php echo $img_count; ?>

                            </ul>
                        </div>
                        <div class="aboutslider-shadow">
                            <span class="s1"></span>
                        </div>
                    <?php else :?>
                        <div class="portfolio_item">
                            <div class="entry">
                                <img src="<?php echo $imagePath; ?>" alt="" class="img-responsive">
                                <div class="magnifier">
                                    <div class="buttons">
                                        <a href="<?php echo $imagePath; ?>" class="sf" title="" data-gal="prettyPhoto[product-gallery]"><span class="fa fa-search"></span></a>
                                        <a class="st" rel="bookmark" target="_blank" href="http://caoutchouc.co.uk"><span class="fa fa-heart"></span></a>
                                        <a class="sg" rel="bookmark" target="_blank" href="http://caoutchouc.co.uk"><span class="fa fa-eye"></span></a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php endif; ?>
                </div>
                <div class="col-lg-12 padding-right-0">
                    <?php /*?><div class="title">
                        <h2><?php echo $title; ?></h2>
                    </div><?php */?>
                    <?php
                        // Hide comments, tags, and links now so that we can render them later.
                        hide($content['field_live_demo']);
                        hide($content['field_tags']);
                        hide($content['field_category']);
                        hide($content['field_skill']);
                        hide($content['field_image']);
                        hide($content['field_gallery']);
                        hide($content['field_audio']);
                        hide($content['field_video']);
                        hide($content['field_layout']);
                        hide($content['links']);
                        hide($content['comments']);
                        print render($content);
                    ?>
                    <?php /*?><?php if(theme_get_setting('showsocial')): ?>
                    <div class="clearfix">
                        <div class="social-2 f-left a2a_kit">
                            <a class="a2a_dd" href="http://www.addtoany.com/share_save"><i class="fa fa-plus-square"></i></a>
                            <a class="a2a_button_linkedin"><i class="fa fa-linkedin"></i></a>
                            <a class="a2a_button_pinterest"><i class="fa fa-pinterest"></i></a>
                            <a class="a2a_button_google_plus"><i class="fa fa-google-plus"></i></a>
                            <a class="a2a_button_twitter"><i class="fa fa-twitter"></i></a>
                            <a class="a2a_button_facebook"><i class="fa fa-facebook"></i></a>
                        </div>
                    </div>
                    <?php endif; ?><?php */?>
                    <div class="product_details">
                        <?php /*?><h3><?php print t('Gallery Details'); ?></h3><?php */?>
                        <ul>
                            <?php /*?><li><strong><?php print t('Added by'); ?>:</strong> <?php print strip_tags($name); ?></li>
                            <?php if(isset($node->field_live_demo['und'])) : ?>
                                <li><strong><?php print t('Live demo'); ?>:</strong> <a href="<?php print $node->field_live_demo['und'][0]['value']; ?>"><?php print $node->field_live_demo['und'][0]['value']; ?></a></li>
                            <?php endif; ?>
                            <?php if(isset($node->field_category['und'])) : ?>
                                <li><strong><?php print t('Category'); ?>:</strong> <?php print jollyany_format_comma_field('field_category', $node); ?></li>
                            <?php endif; ?>
                            <?php if(isset($node->field_skill['und'])) : ?>
                                <li><strong><?php print t('Skill'); ?>:</strong> <?php print jollyany_format_comma_field('field_skill', $node); ?></li>
                            <?php endif; ?><?php */?>
                            <br /><span class="smallprint"><?php print t('Date posted'); ?>: <?php print format_date($node->created, 'custom', 'd M, Y'); ?></span>
                            <?php /*?><?php if(isset($node->field_tags['und'])) : ?>
                                <li><strong><?php print t('Tags'); ?>:</strong> <?php print jollyany_format_comma_field('field_tags', $node); ?></li>
                            <?php endif; ?><?php */?>
                        </ul>               
                    </div>
                </div>

                <div class="clearfix"></div>
                <?php if($page && module_exists('prev_next')): ?>   
                    <div class="next_prev text-center">
                        <ul class="pager">
                            <?php if(isset($prev_url)) : ?>
                                <li class="previous">
                                    <a href="<?php echo $prev_url; ?>">← Previous</a>
                                </li>
                            <?php endif; ?>
                            <?php if(isset($next_url)) : ?>
                                <li class="next">
                                    <a href="<?php echo $next_url; ?>">Next →</a>
                                </li>
                            <?php endif; ?>
                        </ul>
                    </div>
                <?php endif; ?>         

            </div>

    <?php else :?>

            <div class="col-lg-12 col-sm-12 col-md-12 col-xs-12 single-portfolio">
                <div class="full_portfolio">
                <div class="backtogalleries"><a href="/image-gallery" target="_self" class="btn-primary btn-xs">back to gallery overview</a></div>
                    <?php if(isset($node->field_video['und']) && !empty($node->field_video['und'][0]['value'])) :?>
                        <div class="portfolio_item">
                            <div class="entry">
                                <?php print $node->field_video['und'][0]['value']; ?>
                                <div class="post-type">
                                    <i class="fa fa-play"></i>
                                </div>
                            </div>
                        </div>
                    <?php elseif(isset($node->field_audio['und']) && !empty($node->field_audio['und'][0]['value'])) :?>
                        <div class="portfolio_item">
                            <div class="entry">
                                <?php print $node->field_audio['und'][0]['value']; ?>
                                <div class="post-type">
                                    <i class="fa fa-music"></i>
                                </div>
                            </div>
                        </div>
                    <?php elseif($image_slide != '') : ?>
                        <div id="aboutslider" class="flexslider clearfix">
                            <ul class="slides">
                                <?php while ($img_count < $counter) { ?>
                                   <?php /*?><li><img src="<?php echo image_style_url('image_650x312',$node->field_gallery['und'][$img_count]['uri']); ?>" class="img-responsive" alt=""></li><?php */?>
                                   <li><img src="<?php echo file_create_url($node->field_gallery['und'][$img_count]['uri']); ?>" class="img-responsive" alt=""></li>

                                <?php $img_count++; } ?>
                            </ul>
                        </div>
                        <div class="slider-shadow"></div>
                            <?php else :?>
                        <div class="portfolio_item">
                            <div class="entry">
                                <img src="<?php echo $imagePath; ?>" alt="" class="img-responsive">
                                <div class="magnifier">
                                    <div class="buttons">
                                        <a href="<?php echo $imagePath; ?>" class="sf" title="" data-gal="prettyPhoto[product-gallery]"><span class="fa fa-search"></span></a>
                                        <a class="st" rel="bookmark" target="_blank" href="http://caoutchouc.co.uk"><span class="fa fa-heart"></span></a>
                                        <a class="sg" rel="bookmark" target="_blank" href="http://caoutchouc.co.uk"><span class="fa fa-eye"></span></a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php endif; ?>
                </div>

                <div <?php /*?>class="col-lg-12"<?php */?>>
                    <?php /*?><div class="title">
                        <h1><?php echo $title; ?></h1>
                    </div>  <?php */?>
                    <?php
                        // Hide comments, tags, and links now so that we can render them later.
                        hide($content['field_live_demo']);
                        hide($content['field_tags']);
                        hide($content['field_category']);
                        hide($content['field_skill']);
                        hide($content['field_image']);
                        hide($content['field_gallery']);
                        hide($content['field_audio']);
                        hide($content['field_video']);
                        hide($content['field_layout']);
                        hide($content['links']);
                        hide($content['comments']);
                        print render($content);
                    ?>
                    <?php /*?><?php if(theme_get_setting('showsocial')): ?>
                    <div class="clearfix">
                        <div class="social-2 f-left a2a_kit">
                            <a class="a2a_dd" href="http://www.addtoany.com/share_save"><i class="fa fa-plus-square"></i></a>
                            <a class="a2a_button_linkedin"><i class="fa fa-linkedin"></i></a>
                            <a class="a2a_button_pinterest"><i class="fa fa-pinterest"></i></a>
                            <a class="a2a_button_google_plus"><i class="fa fa-google-plus"></i></a>
                            <a class="a2a_button_twitter"><i class="fa fa-twitter"></i></a>
                            <a class="a2a_button_facebook"><i class="fa fa-facebook"></i></a>
                        </div>
                    </div>
                    <?php endif; ?><?php */?>
                    <div class="product_details">
                        <?php /*?><h3><?php print t('Gallery Details'); ?></h3>
                        <ul><?php */?>

                            <?php /*?><li><strong><?php print t('Added by'); ?>:</strong> <?php print strip_tags($name); ?></li>
                            <?php if(isset($node->field_live_demo['und'])) : ?>
                                <li><strong><?php print t('Live demo'); ?>:</strong> <a href="<?php print $node->field_live_demo['und'][0]['value']; ?>"><?php print $node->field_live_demo['und'][0]['value']; ?></a></li>
                            <?php endif; ?>
                            <?php if(isset($node->field_category['und'])) : ?>
                                <li><strong><?php print t('Category'); ?>:</strong> <?php print jollyany_format_comma_field('field_category', $node); ?></li>
                            <?php endif; ?>
                            <?php if(isset($node->field_skill['und'])) : ?>
                                <li><strong><?php print t('Skill'); ?>:</strong> <?php print jollyany_format_comma_field('field_skill', $node); ?></li>
                            <?php endif; ?>
                            <li><?php */?>
                            <br /><span class="smallprint"><?php print t('Date posted'); ?>: <?php print format_date($node->created, 'custom', 'd M, Y'); ?></span>
                            <?php /*?></li>
                            <?php if(isset($node->field_tags['und'])) : ?>
                                <li><strong><?php print t('Tags'); ?>:</strong> <?php print jollyany_format_comma_field('field_tags', $node); ?></li>
                            <?php endif; ?>
                        </ul><?php */?>

                    </div>
                </div>


                <div class="clearfix"></div>

                <?php if($page && module_exists('prev_next')): ?>   
                    <div class="next_prev text-center">
                        <ul class="pager">
                            <?php if(isset($prev_url)) : ?>
                                <li class="previous">
                                    <a href="<?php echo $prev_url; ?>">← Previous</a>
                                </li>
                            <?php endif; ?>
                            <?php if(isset($next_url)) : ?>
                                <li class="next">
                                    <a href="<?php echo $next_url; ?>">Next →</a>
                                </li>
                            <?php endif; ?>
                        </ul>
                    </div>
                <?php endif; ?>                     

            </div>

    <?php endif; ?>
    </div>
<?php endif; ?>`
13
  • How are the individual galleries created? as a page view?
    – No Sssweat
    Mar 11, 2016 at 10:24
  • As far as I can see the masonry overview is a view, but the actual gallery is a node (the actual page/node/content type instance I add under content), with a template.php turning the pictures into the sliding gallery..
    – xax
    Mar 11, 2016 at 10:26
  • Unless we can see that template.php code, it would be hard to help. So if you can add it to your Q, that would be helpful.
    – No Sssweat
    Mar 11, 2016 at 10:37
  • have tried to add as code but mucks up the code a bit? Seems OK now :)
    – xax
    Mar 11, 2016 at 11:09
  • after global $image_default; if you add $node = node_load(16); upload and overwrite, flush the cache, does it load node's 16 slideshow on all the pages?
    – No Sssweat
    Mar 11, 2016 at 11:57

1 Answer 1

1

Yes, the idea is I have a page (basic page node) for each class at the school, I include a block that shows 1 image gallery, only the one that belongs to that class. So if node 'nursery is opened, I would like the block to show image gallery 'nursery', and if node 'year one' is opened image gallery 'year one'.. So how do I code a Node ID into the template?

<?php

if ($node = menu_get_object()) {
  // Get the nid
  $nid = $node->nid;

  $node = node_load($nid);

}


?>

This will automatically pass the nid that you're on (have opened).

3
  • No Sssweat. I have upped your answer, but am too newbie for it to count as yet.
    – xax
    Mar 16, 2016 at 11:29
  • Your script works fine, but I realised now that I should have asked my question a little different, sorry. What I actually need is a piece of code at the top of my block script that looks at the title of the class page I'm on (say /classes/year-one) and then shows the gallery with the same title (e.g. /image-gallery/year-one.
    – xax
    Mar 16, 2016 at 11:32
  • I have found another way, not as elegant as fully automatically calling the correct gallery based on name of page and name of gallery, but still elegant enough. What I've done: added a field to the gallery content type asking for which class page it belongs to; added a relationship with that field to the block view, added a contextual filter on Nid with that relationship.. Now the block shows up the correct gallery only on the node marked on the gallery creation/edit form..
    – xax
    Mar 16, 2016 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.