[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: Некорректная работа скрипта, поиска в БД
Гость_west
Доброго времени суток, уважаемые кодеры. Возникла проблема которую очень нужно решить, но в силу малого опыта в php, решить самостоятельно довольно сложно. С начала адресовал этот вопрос на форумах по wordpress, но они какие то не живые. за помощь, готов что нибудь отфотошопить или сверстать если надо ;) .

Установили плагин NextGallery, всё устраивает, но никак не можем вкрутить в него поиск. Точнее вкрутили, но работает он некорректно.
Вкрутили путём изменения двух файлов, в теме (functions.php и search.php).

В search.php добавили:
// Start of NextGen Gallery search
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, ''); // put the number of pictures by row you want, if you don't want "4"

echo "<h2>Pictures</h2>";
if ($nggpictures) {
echo $nggpictures;
echo '<div class="clear"> </div>';
}
else {
echo '<p>No pictures were found.</p>';
}
}
}
// End of NextGen Gallery search


В functions.php добавили:
## Function to do search 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'
## start of tags code
UNION
SELECT pid,wp_ngg_pictures.description,alttext
FROM wp_ngg_pictures, wp_terms, wp_term_taxonomy, wp_term_relationships
WHERE wp_terms.term_id = wp_term_taxonomy.term_id and
wp_term_taxonomy.taxonomy = 'ngg_tag' and
wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id and
wp_term_relationships.object_id = wp_ngg_pictures.pid and
MATCH (wp_terms.name) AGAINST ('$keywords*' IN BOOLEAN MODE)
AND exclude = '0'
## end of tags code
";

$pictures = $wpdb->get_results($nngquery, ARRAY_A);

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


$out .= '<div class="ngg-gallery-thumbnail">';
$out .= '<a href="'.nggGallery::get_image_url($pic[pid]).'" title="'.stripslashes($pic[description]).'" class="shutterset_set_1" rel="singlepic'.$pic[pid].'">';
$out .= '<img src="'.nggGallery::get_thumbnail_url($pic[pid]).'" alt="'.stripslashes($pic[alttext]).'" title="'.stripslashes($pic[alttext]).'" />';
$out .= "</a></div>\n";
// pictures use float left, so don't need the code that outputs a <br />
// if ($count == 0) {
// $out .= "<br />";
// }
// ++$count;
// $count%=$numberPicRow;
}
return $out;
};


А теперь сам трабл. В галереи есть области для картинок описание и тэг. Допустим в есть 3 картинки, у первой тэг test,у второй test1, у третьей test2. При поиске по ключу test находятся 3 кртинки. При поиске по ключу test1 скрипт вообще не срабатывает. Есть какие нибудь умные мысли и предложения?
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2024 Invision Power Services, Inc.