ModX Evo: Search resources and TV's - display results with ditto
-
01-07-2021 - |
문제
Using ditto I have created a product catalogue. I now wish to add search and filtering options. Would anyone know the best way to do this? I cannot seem to find a good plugin.
I am running ModX Evolution 1.0.6
해결책
I gave up and made my own if anyone's interested:
Updated with full code
Please feel free to ask me to clarify anything or add changes or improvments.
Note there is one problem that I must fix - that you cannot combine the TV's serach terms to make a very definitive search. I will still work on this
//TV FILTERS
$sql = 'SELECT DISTINCT `contentid` FROM `modx_site_tmplvar_contentvalues`';
$where = array();
//ADD THE VARIABLES YOU WANT TO SEARCH TV's WITH BELOW
if ($searchlocation !== 'Any') $where[] = '`value` LIKE "%'.$searchlocation.'%"';
if ($searchmake !== 'Any') $where[] = '`value` LIKE "%'.$searchmake.'%"';
if ($searchtype !== 'Any') $where[] = '`value` LIKE "%'.$searchtype.'%"';
if (count($where) > 0) {
$sql .= ' WHERE '.implode(' OR ', $where);
} else {
// OPTIONAL
// Error out; must specify at least one!
}
$tvqresult = mysql_query($sql);
$num_rowstvq = mysql_num_rows($tvqresult);
while ($rowtvq = mysql_fetch_array($tvqresult)) {
$contid = $rowtvq['contentid'];
//MAIN QUERY RETRIEVES RESOURCE - TEMPLATE LIMITS SEARCH TO PARTICULAR TYPE THAT WILL BE USED IN DITTO
$mainsql = 'SELECT * FROM `modx_site_content` WHERE `id` = ' . $rowtvq['contentid'] . ' AND `template` = 12';
$resultmain = mysql_query($mainsql);
$num_rowsmain = mysql_num_rows($resultmain);
if (!$resultmain) {
continue;
}
elseif ($num_rowsmain == 0){
echo "Sorry - nothing matches your search";
}
else {
while ($row = mysql_fetch_array($resultmain )) {
echo "[[Ditto? &parents=`134` &documents=" . $row['id'] . " &tpl=`usedtempchunk`]]";
}//END MAIN LOOP
}//END MAIN ELSE
}//END TV WHILE LOOP
?>
제휴하지 않습니다 StackOverflow