WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: NextGen Gallery] add search possibility also to pictures ! how to (24 posts)

  1. jcv
    Member
    Posted 5 years ago #

    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!

  2. AengusM
    Member
    Posted 5 years ago #

    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

  3. jcv
    Member
    Posted 5 years ago #

    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.

  4. AengusM
    Member
    Posted 5 years ago #

    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

  5. marlon.c.lindo
    Member
    Posted 5 years ago #

    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

  6. AengusM
    Member
    Posted 5 years ago #

    G'day Marlon,

    sent you an email with some files attached.

    Good luck!

    Aengus

  7. marlon.c.lindo
    Member
    Posted 5 years ago #

    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

  8. tommo77funk
    Member
    Posted 5 years ago #

    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

  9. tommo77funk
    Member
    Posted 5 years ago #

    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

  10. tommo77funk
    Member
    Posted 5 years ago #

    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

  11. Boris
    Member
    Posted 5 years ago #

    replace all instances of nggallery with nggGallery and you'll be fine...

  12. rdsherwood
    Member
    Posted 5 years ago #

    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?

  13. tommo77funk
    Member
    Posted 5 years ago #

    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 ?

  14. tommo77funk
    Member
    Posted 5 years ago #

    hi rdsherwood,

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

  15. rdsherwood
    Member
    Posted 5 years ago #

    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

  16. AengusM
    Member
    Posted 5 years ago #

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

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

    Cheers,

    Aengus

  17. girlvsworld
    Member
    Posted 5 years ago #

    Hi, is this working with wordpress 2.7 and nextgen 1.2.0? Every search term I enter returns 0 results.

  18. crazytaxi
    Member
    Posted 5 years ago #

    For the love of God, will someone PLEASE make this work? NextGen gallery is currently showing over 600 THOUSAND DOWNLOADS. Surely there is some demand for this in a working version.

  19. zuiderwijk
    Member
    Posted 5 years ago #

    I did get the code working, but the only problem I have is that alle the thumbnails are being displayed in one column, and not (let's say) 4 per row.

    Can someone help me on how to fix this problem?

    The website is www2.cakecompany.nl and the searchbox is in the upper right corner. Thanks!

  20. crazytaxi
    Member
    Posted 5 years ago #

    I have the exact same problem as zuiderwijk

  21. post@sarahcole.com.au
    Member
    Posted 5 years ago #

    I have implemented this search and all is well, however does anyone know how to exclude an image from search results

    I see the line
    AND exclude = '0'

    however not sure how to use it.

  22. nims
    Member
    Posted 5 years ago #

    @zuiderwijk @crazytaxi
    Fix for single column problem. In search.php replace
    $nggpictures = ngg_get_search_pictures($keywords,'');
    with
    $nggpictures = ngg_get_search_pictures($keywords,4); // Or any number of your choice

    I made some changes to function call also. See the file http://www.newindianmodels.com/nggtagsearch.txt

    But there is another problem I am having, the search seems to be title and description dependent. It doesnot take into account the ngg tags.

  23. AengusM
    Member
    Posted 5 years ago #

    I've blog'd how I do my search noting I just search images;
    http://blog.aengusm.com/?p=253
    I've added the code from my pages to the post.
    Hope it can help some?
    Cheers,
    Aengus

  24. nancyb7
    Member
    Posted 4 years ago #

    I have posted my search code for NextGen Gallery 1.3.5 in a more recent thread. I could not have found the correct code without this thread, Psykotik's post referenced in the first post above, the newer thread http://wordpress.org:80/support/topic/230905, and the links it contains.

Topic Closed

This topic has been closed to new replies.

About this Topic