Support » Plugins » [Plugin: NextGEN Gallery] nggtags AND and OR

  • First of all; this is a great plugin! Thanks!

    I am using nggtags for displaying pictures (no surprises there :))

    I am using the keyword like this >>[nggtags gallery=thailand,rate_1]<<. This will give me all pictures tagged with “thailand” and “rate_1”, this can be seen as a boolean OR. Is it possible to only display the images that contains both tags (both “thailand” and “rate_1”) like a nboolean AND?

    Thanks!
    John

    http://wordpress.org/extend/plugins/nextgen-gallery/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi,

    I need exactly this function.
    I change the e funciton in the tags.php file like this (word in bold). I’m not a good php programer and i’m sure my code is not the better one, but the result is ok 🙂

    function find_images_for_tags($taglist, $mode = “ASC”) {
    // return the images based on the tag
    global $wpdb;

    // check separator ‘,’ or ‘+’
    if (strpos($taglist, ‘+’) === false) {
    // extract it into a array
    $taglist = explode(“,”, $taglist);
    $separ = false;
    } else {
    // extract it into a array
    $taglist = explode(“+”, $taglist);
    $separ = true;
    }

    if ( !is_array($taglist) )
    $taglist = array($taglist);

    $taglist = array_map(‘trim’, $taglist);
    $new_slugarray = array_map(‘sanitize_title’, $taglist);
    $sluglist = “‘” . implode(“‘, ‘”, $new_slugarray) . “‘”;

    // first get all $term_ids with this tag
    $term_ids = $wpdb->get_col( $wpdb->prepare(“SELECT term_id FROM $wpdb->terms WHERE slug IN ($sluglist) ORDER BY term_id ASC “));
    if ( $separ ) {
    $picids = get_objects_in_term($term_ids[0], ‘ngg_tag’);
    for ( $i=1; $i<count($term_ids); $i++ ){
    $picids = array_intersect($picids, get_objects_in_term($term_ids[$i], ‘ngg_tag’));
    }
    } else {
    $picids = get_objects_in_term($term_ids, ‘ngg_tag’);
    }

    //Now lookup in the database
    if ($mode == ‘RAND’)
    $pictures = nggdb::find_images_in_list($picids, true, ‘RAND’ );
    else
    $pictures = nggdb::find_images_in_list($picids, true, ‘ASC’ );

    return $pictures;
    }

    using the tags is now :
    [nggtags gallery=thailand,rate_1] the same as before !
    [nggtags gallery=thailand+rate_1] only picture with the two tags

    hope this help

    Thread Starter rauhe

    (@rauhe)

    Great! exactly what i was looking for. I cant test it right now but will try it when i get a chance……

    Thanks!
    John

    Excellent, merci beaucoup, c’est LE code que je cherchais depuis longtemps !!!

    Excellent, thank’s a lot, this THE code I searching for a long time !!!

    … and, otherwise, is there a way to exclude a tag ?
    Like this for exemple : [nggtags gallery=thailand-rate_1] all the pictures with thailand tag but without rate_1

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: NextGEN Gallery] nggtags AND and OR’ is closed to new replies.