Search News Posts Only From News Page

thorn

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)

<form name="search" action="<?php echo WB_URL.'/search/index'.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.
[url=http://nettest.thekk.de/doku.php]Projekte[/url]

jar

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

gillweb

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
$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:
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: