WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Droplets & Snippets => Topic started by: gillweb on October 28, 2007, 10:08:12 PM

Title: Search News Posts Only From News Page
Post by: gillweb on October 28, 2007, 10:08:12 PM
I can't say this is the PERFECT solution but it seems to work for me  :-D

Make a new CODE page that is hidden name "search news" (i added it as a child page of my news page).  Add this code to this page
Code: [Select]
$string = @$_POST['string'];
$query = "SELECT * FROM mod_news_posts WHERE content_long LIKE '%$string%'";
$result = mysql_query($query);
$rows=mysql_num_rows($result);

if ($rows == 0) { echo" No Results"; }

   $error = mysql_error();
      if (!$result = mysql_query($query)) {
           print "$error";
       }

while($data = mysql_fetch_object($result)){
$title = $data->title;
$link = $data->link;
$short= $data->content_short;

echo '<p>';
echo '<b>'.$title.'</b><br />';
echo ''.$short.' ';
echo '<a href="'.WB_URL.'/pages/'.$link.PAGE_EXTENSION.'">Read More...</a></p>';

}
Then add a Code sectin to you main news page where you want your search box to show and enter this code:
Code: [Select]
echo "<br /><center><form method=\"post\" action=\"";
echo WB_URL;
echo "/pages/news/search-news";
echo PAGE_EXTENSION;
echo  "\">";
echo "<input type=\"text\" maxlength=\"64\" name=\"string\" />&nbsp;&nbsp;&nbsp;";
echo "<input type=\"submit\" value=\"Search News\" />";
echo "</form></center><br />";
You should be good to go now  :mrgreen:
Title: Re: Search News Posts Only From News Page
Post by: jar on June 27, 2008, 10:55:16 AM
i have a error


Fatal error: Cannot redeclare search_highlight() (previously declared in /home/tusirom1/public_html/framework/frontend.functions.php:70) in /home/tusirom1/public_html/framework/frontend.functions.php on line 92
Title: Re: Search News Posts Only From News Page
Post by: thorn on June 27, 2008, 07:12:16 PM
Hello,

there is a handy - yet not(?) documented - new search-feature since wb2.7:
see https://forum.WebsiteBaker.org/index.php/topic,10058.msg59052.html#msg59052

To search in news-postings only you can do this to add a search-box: (if the news-pages appears as http://www.example.org/pages/news.php)
Code: [Select]
<form name="search" action="<?php echo WB_URL.&#39;/search/index&#39;.PAGE_EXTENSION; ?>" method="get">
  <input type="hidden" name="search_path" value="/news">
  <input type="text" name="string" value="search" /><br />
  <input type="submit" value="Search" /><br />
  <input type="radio" name="match" id="match_all" value="all" checked="checked" /><label for="match_all">All Words</label>
  <input type="radio" name="match" id="match_any" value="any" /><label for="match_any">Any Words</label>
  <input type="radio" name="match" id="match_exact" value="exact" /><label for="match_exact">Exact Match</label>
</form>

thorn.