Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

NextGen Gallery (NGG) / Image Search / Image Browser WordPress

I'm after exactly the same solution as was asked for here

http://wpquestions.com/question/show/id/2570

However I've tried the code suggested and it no longer seems to work with the latest version of NGG/Search engine/WP

Post with image browser working:

http://bluebusstudios.com/WPTEST/?p=4

Image search results page, thumbnail links not working (with image browser enabled)

http://bluebusstudios.com/WPTEST/?s=pixar&pid=3

Summary:

NGG Gallery + Image Search Engine + Image browser mode = Thumbnails in search results do not open. Thumbnail results in posts work as they should.

(sorry, can't get the links to be clickable...)

Answers (1)

2013-05-02

Dbranes answers:

Hi, the thumbnail links contain the search parameter <strong>s</strong> :

http://bluebusstudios.com/WPTEST/?s=pixar&pid=3

and therefore you get the search page again when you click the thumbnail links.

But I guess you want the above link to be

http://bluebusstudios.com/WPTEST/?pid=3

Can you post the code you use for the thumbnail link generation?


thebluebus comments:

I think it needs to be

http://bluebusstudios.com/WPTEST/?p=4&pid=3

as this works on the post page. Assuming ?p=4 is the post id? then &pid=3 is the image id?

This is the standard thumbnail part of the code in:

www.bluebusstudios.com/WPTEST/wp-content/plugins/nextgen-gallery/view/gallery.php

<!-- Thumbnails -->
<?php foreach ( $images as $image ) : ?>

<div id="ngg-image-<?php echo $image->pid ?>" class="ngg-gallery-thumbnail-box" <?php echo $image->style ?> >
<div class="ngg-gallery-thumbnail" >
<a href="<?php echo $image->imageURL ?>" title="<?php echo $image->description ?>" <?php echo $image->thumbcode ?> >
<?php if ( !$image->hidden ) { ?>
<img title="<?php echo $image->alttext ?>" alt="<?php echo $image->alttext ?>" src="<?php echo $image->thumbnailURL ?>" <?php echo $image->size ?> />
<?php } ?>
</a>
</div>
</div>


Have a look in the previous question that was soved (referenced in my first post) to see the suggested work around which no longer works.

Hope this helps


Dbranes comments:

maybe something like:

$new_tmp_link = home_url().'/?p='.get_the_ID().'&pageid='.get_the_ID().'&pid='.$tmp_gid;

instead of

$new_tmp_link = 'http://www.heliocristovao.net/portfolio/'.$tmp_gallery_slug.'/gallery/image/'.$tmp_img_slug.'';


Dbranes comments:

meant

$new_tmp_link = home_url().'/?p='.get_the_ID().'&pageid='.get_the_ID().'&pid='.$image->pid;


instead of

$new_tmp_link = 'http://www.heliocristovao.net/portfolio/'.$tmp_gallery_slug.'/gallery/image/'.$tmp_img_slug.'';

;-)


thebluebus comments:

thanks, I've made the changes and it produces this link

http://bluebusstudios.com/WPTEST/?pageid=&pid=3

which loads the post, but not the imagebrowser page such as

http://bluebusstudios.com/WPTEST/?p=4&pid=3


Dbranes comments:

Here is just some debug code for you:



global $post;

if(isset$post)){
echo "<pre>post->ID = ". $post->ID."</pre>";
}else{
echo "<pre>post object is not set!</pre>";
}

echo "<pre>get_the_ID() = ". get_the_ID()."</pre>";
echo "<pre>image:".print_r($image,true)."</pre>";



to add into the <strong>foreach ( $images as $image )</strong> loop.


Dbranes comments:

ps: I forgot a <strong>(</strong> in <strong>isset$post)</strong>

take two:

global $post;

if(isset($post)){
echo "<pre>post->ID = ". $post->ID."</pre>";
}else{
echo "<pre>post object is not set!</pre>";
}

echo "<pre>get_the_ID() = ". get_the_ID()."</pre>";
echo "<pre>image:".print_r($image,true)."</pre>";


thebluebus comments:

sorry, can you just explain how to add it to the loop? as it is currently

<?php foreach ( $images as $image ) : ?>


thebluebus comments:

oh I think i've done it. Is that is?

http://bluebusstudios.com/WPTEST/?s=pixar


Dbranes comments:

jebb,

It looks like the global $post object is not set.

I also wanted to check if you had any post_id/pageid available in the $image object but:


[post_id] => 0
[pageid] => 0


So let's look at the nggsearch engine, what template are you using there?


thebluebus comments:

I used the 'default' search.php template included with nggsearch and replaced the one in the theme folder

<?php
/**
* @package WordPress
* @subpackage Default_Theme
*/

get_header(); ?>

<div id="content" class="narrowcolumn" role="main">

<?php if (have_posts()) : ?>

<h2 class="pagetitle">Search Results</h2>

<div class="navigation">
<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
</div>


<?php while (have_posts()) : the_post(); ?>

<div <?php post_class() ?>>
<h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
<small><?php the_time('l, F jS, Y') ?></small>

<p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?></p>
</div>

<?php endwhile; ?>

<div class="navigation">
<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
</div>

<?php if ( function_exists( 'ngg_images_results' ) && have_images() ) : ?>

<h2 class="pagetitle">Image Search Results</h2>
<?php ngg_images_results(); ?>

<?php endif; ?>

<?php elseif ( function_exists( 'ngg_images_results' ) && have_images() ) : ?>

<h2 class="pagetitle">Image Search Results</h2>
<?php ngg_images_results(); ?>

<?php else : ?>

<h2 class="center">No posts found. Try a different search?</h2>
<?php get_search_form(); ?>

<?php endif; ?>

</div>

<?php get_sidebar(); ?>

<?php get_footer(); ?>


Dbranes comments:

I tested

<?php if ( function_exists( 'ngg_images_results' ) ) ngg_images_results(); ?>

in my search.php file in the current theme directory on my WP 3.5.1 install with twentytwelve theme, ngg 1.9.12 and nggsearch eninge 0.7.0.

The get_the_ID() seems to be working. I will test your template.


Dbranes comments:

I tested your search template, with some debug code, and <strong>get_the_ID()</strong> is working on my local install:

[[LINK href="http://i.imgur.com/cXkHfZR.gif"]]http://i.imgur.com/cXkHfZR.gif[[/LINK]]

;-)


thebluebus comments:

strange....that was a fresh install i set up so should be the same as yours. confused. What would be causing the difference?


Dbranes comments:

yes strange

I use [nggallery id=1] in my post.

Just some ideas:

Do you have other plugins?
Does it work on other themes?
Have you saved permalinks with the usual permalink structure (maybye totally unrelated) ?



thebluebus comments:

I used the same [nggallery id=1]
No other plugins - Fresh install
Just set it to the twentyeleven theme and its still coming up [post_id] => 0
Haven't changed any permalinks settings.

Server settings possibly? :(


Dbranes comments:

you can try to replace


<?php ngg_images_results(); ?>


with


<?php echo "get_the_ID()=".get_the_ID();?>
<?php ngg_images_results(); ?>


in your <strong>search.php</strong> template just to see if it works there.

You can also try the <strong>plugin-check</strong> in <em>/wp-admin/admin.php?page=nextgen-gallery</em>


Dbranes comments:

You could at least use the direct link to the image

$new_tmp_link = home_url().'/'.$image->path.'/'.$image->filename;

as temporary fix ;-)


Dbranes comments:

I think I found a way for you to use the code unchanged from:

http://wpquestions.com/question/show/id/2570

i.e.

$new_tmp_link = home_url().'/'.$tmp_gallery_slug.'/gallery/image/'.$tmp_img_slug;

<strong>Follow these steps:</strong>

<strong>1)</strong> Edit each gallery (under Manage Galleries) and link it to a page. You can just press the button "Add page".

<strong>2)</strong> Visit General Options in NGG and check the "Acitvate permalinks" and write "gallery" as the slug name.

<strong>3)</strong> Visit Settings / Permalinks under /wp-admin/options-permalink.php.
There you can use the custom permalinks like:

/%year%/%monthnum%/%day%/%postname%/

Press "Save Changes"

<strong>4)</strong> Try the search again.


Then your thumbnail links will look like:

http://example.com/mypage/gallery/image/myimage/

This works on my install.


thebluebus comments:

thanks that does work, even though its a bit of a workaround. how come they need to be tied to pages rather than posts?


Dbranes comments:

ok, great

Part of the problem is that you can insert the same gallery shortcode into many posts.

So assigning the gallery to a page is a way around it ;-)


thebluebus comments:

it just means that whenever i post a new gallery (in a post) i then need to create a page which its linked to. I'll also need to presumably remove the nav menu which shows pages, and create my own manually, otherwise it'll show all the 'pages' that are simply there for this hack...


Dbranes comments:

seems to be the way to go, maybe you can have a parent page above all gallery pages.

<strong>ps:</strong>

You can always play with something like this and save permalinks:

add_action( 'init', 'my_rewrite_rule' );
function my_rewrite_rule() {
add_rewrite_rule('show-gallery/([0-9]+)$', 'index.php?mygid=$matches[1]', 'top');
}

add_action('query_vars', 'my_query_vars');
function my_query_vars($query_vars){
$query_vars[] = 'mygid';
return $query_vars;
}

add_action('template_redirect','my_ngg_template');
function my_ngg_template(){
if(get_query_var('mygid')){
get_header();
echo "<h1>Show gallery:</h1>";
echo do_shortcode(sprintf("[nggallery id=%d]",get_query_var('mygid')));
get_footer();
exit();
}
}


to have url like

http://example.com/show-gallery/2/

to show a gallery but that is a detour ;-)