• JCV

    (@psykonevro)


    For people interested in adding to wordpress search process the possibility to search also pictures, visit this message (don’t know how to add files to this forum, therefore I’m forced to link from here).

    The more you tag/name your pictures, the more accurate the results will be!

Viewing 15 replies - 1 through 15 (of 23 total)
  • Fantastic, I’ve been looking for something like this for some time.

    My girlfriend had a play with your code and enhanced it slightly because I noted that it didn’t appear to search picture tags, just the name, description and the alt.

    Laura isn’t a SQL / PHP person so the code can probably be made even more efficient.

    I don’t think we added anything extra to what you defined for search.php;

    <p></p>
    <?php if(is_search()) {
    $search = $wp_query->get(‘s’);
    $keywords = preg_replace(‘/\+/’,’ ‘,$search);
    if (function_exists (‘ngg_get_search_pictures’)) { // function from functions.php
    $nggpictures = ngg_get_search_pictures($keywords, ‘6’); // put the number of pictures by row you want, if you don’t want “4”
    if ($nggpictures) {
    echo “<h2></h2>”;
    echo $nggpictures;
    }
    }
    }
    ?>

    Several changes in functions.php;

    ## Function to do searchs on gallery pics from NextGen Gallery plugin
    ##
    ## 2 vars : (1) $keywords (usually coming from the standard search query from wordpress)
    ## (2) $numberPicCol (number of pic by row, if null it takes 4 )
    function ngg_get_search_pictures ($keywords, $numberPicRow = NULL) {
    global $wpdb;
    $count=1;
    if (!$numberPicRow) { $numberPicRow = “4”; }

    $nngquery = “
    SELECT pid,description,alttext
    FROM wp_ngg_pictures
    WHERE MATCH (description, filename, alttext) AGAINST (‘*$keywords*’ IN BOOLEAN MODE)
    AND exclude = ‘0’
    UNION
    SELECT pid,description,alttext
    FROM wp_ngg_pictures, wp_ngg_tags, wp_ngg_pic2tags
    WHERE pid = picid and tagid = id and
    MATCH (name) AGAINST (‘*$keywords*’ IN BOOLEAN MODE)
    AND exclude = ‘0’
    “;
    $pictures = $wpdb->get_results($nngquery, ARRAY_A);

    if ($pictures) foreach($pictures as $pic) {

    $out .= ‘‘;
    $out .= ‘<img class=”ngg-gallery” style=”border: .1em solid #FFFFFF” src=”‘.nggallery::get_thumbnail_url($pic[pid]).'” alt=”‘.stripslashes($pic[alttext]).'” title=”‘.stripslashes($pic[alttext]).'” />’;
    $out .= “
    \n”;
    if ($count == 0) {
    $out .= “”;
    }
    ++$count;
    $count%=$numberPicRow;
    }
    return $out;
    };

    Hope the code posts OK?

    I’m redeveloping my website but you can see the code in practise here, http://blog.aengusm.com/?page_id=24 not many pics there at the moment so just enter a single letter like a in the search box.

    Hope that adds something for someone.

    Cheers,

    Aengus

    Thread Starter JCV

    (@psykonevro)

    Great, I wasn’t alone wanting such function 🙂 But you may notice code post are not going well at all; part of functions.php is htmlized…

    About the new sql query:
    Well, I thought about adding a search into wp_ngg_tags field too. But… I finally decided it belongs to a tag.php page, and not to a search.php. If not, when you search something, results given would be related to picture tags, but not to post tags.

    About removing the “extra” :
    Feel you free to modify according to your theme! But for mine, it will stay with the “extra” 🙂

    And let me add that your submarine pictures are great.

    Ah, good point about the blog tags! I should have added, I only want search for pictures, no blog search so I removed that component from the search.php.
    Its all a good start for NextGen Search!
    Aengus

    Hey AengusM

    Been looking for this for some time too, with a deadline looming, I have noticed your really cool website with the search function for pics alone, I’m developing a fashion website and need the same search functions as you just pictures no posts or anything , I’ve followed the instructions from lost highway and here but to no avail, the code does not work on my site, can you please tell me where I have gone wrong, or maybe post your entire search and functions file?

    kalotropic.com/cariolhayes/
    thats the url of my site

    Thanks
    Marlon

    G’day Marlon,

    sent you an email with some files attached.

    Good luck!

    Aengus

    I haven’t recieved your email Aengus, maybe my email address was wrong, Can you please send it again?
    Here is the correct one:
    marlon.c.lindo@googlemail.com
    the correct url is:
    http://www.kalotropic.com/carolhayes/

    I think I was very tired when writing the post last night! Your photos are cool! Tell me what you think of the site in progress…
    Many Thanks!

    Marlon

    Hi,

    Many thanks for this post psykonevro, just what i wanted 🙂 I have to some degree of success implemented a search for my NextGen gallery. I just have 2 problems that i was hoping could be fixed.

    please see here

    Firstly I have tried AengusM’s code and it works, but strangely not for my nextgen tags 🙁

    and secondly when displaying pics as well as posts from a search, (I do want to search both) the resulting pics in the search results are not active, meaning they cannot be clicked, to show larger image.

    The code i got from here to post in search results does not seem to allow a link to larger image to be made. I have been trying for hours to solve this, but no joy.

    I have looked at AengusM gallery and it is excellent, as well as the pics, all works as intended,

    So any tips or advice would be really gratefully received 🙂

    best wishes,

    tom

    Hi,

    Found some code about 3am this morning that fixed my problem, if anyone else is having difficulty with nextgen image search results not being active links, try this code in functions.php

    ## Function to do searches on gallery pics from NextGen Gallery plugin
    ##
    ## 2 vars : (1) $keywords (usually coming from the standard search query from wordpress)
    ## (2) $numberPicCol (number of pic by row, if null it takes 4 )
    function ngg_get_search_pictures ($keywords, $numberPicRow = NULL) {
    global $wpdb;
    $count=1;
    if (!$numberPicRow) { $numberPicRow = “4”; }

    $nngquery = “
    SELECT pid,description,alttext
    FROM wp_ngg_pictures
    WHERE MATCH (description, filename, alttext) AGAINST (‘*$keywords*’ IN BOOLEAN MODE)
    AND exclude = ‘0’
    “;
    $pictures = $wpdb->get_results($nngquery, ARRAY_A);

    if ($pictures) foreach($pictures as $pic) {

    $out .= ‘‘;
    $out .= ‘<img class=”ngg-singlepic” src=”‘.nggallery::get_thumbnail_url($pic[pid]).'” alt=”‘.stripslashes($pic[alttext]).'” title=”‘.stripslashes($pic[alttext]).'” />’;
    $out .= “
    \n”;
    if ($count == 0) {
    $out .= “
    “;
    }
    ++$count;
    $count%=$numberPicRow;
    }
    return $out;
    };

    Best wishes,

    tom

    Hi psykonevro and AengusM,

    Is your search still working after upgrading to wordpress 2.7 and next-gen v1.01 ?

    Mine is not anymore and I am desperate for solution, any advice v.grateful 🙂

    best wishes,

    tom

    Boris

    (@travel-junkie)

    replace all instances of nggallery with nggGallery and you’ll be fine…

    I’ve tried implementing this search code, but when I place the code referenced above into my functions.php file, when I run WordPress, the code is listed at the top of the screen, and WordPress doesn’t work. There is already some code in my functions.php, and I’ve tried copying-and-pasting this search code both before and after the code that is already in the file – with the same results both ways. I know next to nothing about PHP, so I have no insight into what I’m doing wrong. Can anyone give me any pointers to get it working?

    thanks travel junkie ! found answer a little while ago, on another forum 🙂 but many thanks for solution.

    hi rdsherwood, have you looked at this tutorial ?

    hi rdsherwood,

    also check that the code you posted is between <?php and ?> otherwise code could show on your page.

    Hi tommo77funk:

    Thank you very much for your help. I had made the newbie mistake of not putting the code between <?php and ?>. Obviously, I know next to nothing about php!

    Anyway, it’s basically working, but I’m still having a couple of problems:
    1) Regardless of whether I leave the default for number of photos per row, or put a number in the code, I get one picture per line.
    2) The search doesn’t seem to be working right. For example, I have lots of images of eagles, but if I do a search on eagle, it returns nothing. But some searches do appear to be returning results. I think it may be related to whether the images are used in a post, rather than just in the gallery. The tutorial at http://www.ikiru.ch talked about splitting the code to display the pictures even if there are no posts. This may be related to my problem, but I’m not a good enough coder to figure out how to do what he eludes to.

    My web site is http://www.sherwoodimagery.com. The search box is in the right sidebar. Any suggestions or pointers would be greatly appreciated!

    Ron

    This post maybe of assistance with regard to search and 1.0;

    http://wordpress.org/support/topic/230905?replies=1#post-944495

    Cheers,

    Aengus

Viewing 15 replies - 1 through 15 (of 23 total)
  • The topic ‘[Plugin: NextGen Gallery] add search possibility also to pictures ! how to’ is closed to new replies.